-
-
Notifications
You must be signed in to change notification settings - Fork 144
2. Creating the Application
Fire up Visual Studio, and create a new WPF Application.
Open the NuGet package manager (right-click your project, and click "Manage NuGet Packages", and install Stylet. We'll also use PropertyChanged.Fody to raise our PropertyChanged events for us (see the section in PropertyChangedBase), so also install this.
Now we follow the instructions from Quick Start. Create a new Window, called ShellView.xaml
, and a new class called ShellViewModel.cs
.
ShellView.xaml
:
<Window x:Class="Stylet.Samples.RedditBrowser.Pages.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ShellView" Height="500" Width="500">
<Grid>
<TextBlock>Hello, World</TextBlock>
</Grid>
</Window>
ShellViewModel.cs
:
public class ShellViewModel : Screen
{
public ShellViewModel ()
{
this.DisplayName = "Reddit Browser";
}
}
I've derived the ShellViewModel from Screen mainly out of habit - we'll change this in a later part of the tutorial.
Next up, we'll need a bootstrapper. Create Bootstrapper.cs
, which should look like this:
public class Bootstrapper : Bootstrapper<ShellViewModel>
{
}
Finally, delete MainWindow.xaml
, and edit App.xaml
. Remove the StartupUri
property, add the appropriate namespaces, and configure it to use your bootstrapper. It should look like this:
<Application x:Class="Stylet.Samples.RedditBrowser.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:local="clr-namespace:Stylet.Samples.RedditBrowser">
<Application.Resources>
<s:ApplicationLoader>
<s:ApplicationLoader.Bootstrapper>
<local:Bootstrapper/>
</s:ApplicationLoader.Bootstrapper>
</s:ApplicationLoader>
</Application.Resources>
</Application>
That's it! Build and run your application, and you should see a window appear with the text "Hello, World".