Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Using OmniXAML for WPF

Daniel Kornev edited this page May 23, 2017 · 5 revisions
  1. Create a new project of type "WPF Application" and be sure that you select at least .NET Framework 4.5.2
  2. Install the NuGet package: OmniXaml.Wpf.
  3. Go to the Properties page of MainWindow.xaml and set the property Copy to Output Directory to either Copy always or Copy if newer.
  4. Delete MainWindow.xaml.cs (the code-behind file). It won't compile if you don't delete it.
  5. Open MainWindow.xaml and replace its content with this:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="MainWindow" Height="350" Width="525">
        <TextBlock Text="Hello World!" />
</Window>
  1. Open App.xaml and remove the part that says StartupUri="MainWindow.xaml"
  2. Open App.Xaml.cs and add this method inside the App class:
    protected override void OnStartup(StartupEventArgs e)
    {
        var xamlLoader = new WpfXamlLoader();

        Window mainWindow;
        using (var stream = new FileStream("MainWindow.xaml", FileMode.Open))
        {
            mainWindow = (Window) xamlLoader.Load(stream);
        }

        mainWindow.Show();
    }

Don't forget to add the using OmniXaml.Wpf; part along with the other using statements ;)

  1. Run it!
Clone this wiki locally