开发者

Visual Studio 2010 uses Application.xaml; Blend 4 uses App.xaml

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 Appl开发者_运维技巧ication.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...


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'.

Visual Studio 2010 uses Application.xaml; Blend 4 uses App.xaml

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜