Frage

Previously all application level resources in a project I am authoring were stored in App.xaml. Then i decided to migrate from VS 2008 to 2010 and that is where the trouble started.

After migrating, I tried to do a little testing using a testing window instead of the normal startup window. After changing the startup object, suddenly I was faced with lots of compile errors and what not which (long story short) resulted in finding that there was now two files which held application level resources associated with the project: App.xaml (the original), and Application.xaml (at this time veritably empty). I migrated all of the resources (as well as merged dictionaries) over to the Application.xaml, and all was again right with the world so far as Visual Studio was concerned.

I then found out that Blend still wanted to use the App.xaml. I had created several resources and placed them in the Application.xaml, and saw that they were not being used when I compiled with Blend (but they were being used when i compiled with VS).

Where does one specify which xaml is the top level WPF resource file? This is getting out of hand...

Cory

War es hilfreich?

Lösung

There are slight differences in naming depending on what programming language you choose. Visual Basic WPF projects use Application.xaml, while C# projects name it App.xaml.

As you probably know all .NET apps need a Main method. Also, windows apps need a message pump to get hooked to the Windows messaging system. IN WPF you can use the Application class to start listening to the windows messages.

Here's how you can do it explicitly.

VB

Public Class Startup

  <STAThread()>
  Shared Sub Main()
    Dim app As New Application()
    Dim window As New MainWindow()

    window.Show()
    app.Run()

  End Sub

End Class

C#

public class Startup
    {


  [STAThread()]
  public static void Main()
  {
    Application app = new Application();
    MainWindow window = new MainWindow();

    window.Show();
    app.Run();

  }
}

Since creating this type of code is common for WPF applications you can tell MSBuild to write this code by defining a XAML file and class that derives from System.Windows.Application and specifing its build action as 'ApplicationDefinition'.

enter image description here

In your situation, instead of editing the VbProj file, you could just select the correct file in Solution Explorer and change the BuildAction.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top