Quickstart
Install Ammy Visual Studio extension
Go to Visual Studio Marketplace and download Ammy. Close Visual Studio if it was opened and install downloaded extension.
Create an empty WPF project
Open Visual Studio, go to File -> New -> Project
Create an empty WPF application by choosing Visual C# -> Windows -> Classic Desktop -> WPF Application
Install Ammy nuget package
Open Package Manager Console (View -> Other Windows -> Package Manager Console)
Execute: install-package Ammy.WPF
Now you have several choices, let’s start with the easiest one
Add Ammy user control and host it inside MainWindow.xaml
We will create a user control that will be a host for all of our UI inside the main window.
In Solution Explorer right click on a project name and choose Add -> New Item…
Ammy Extension should have added few item templates, namely: Ammy Application, Ammy Mixins, Ammy User Control and Ammy Window. Just choose Ammy User Control, give it appropriate name, for example Host.ammy
and click Add. Visual Studio should open your newly created file now.
Insert TextBlock
node inside UserControl
like this:
TextBlock { "Hello, World!" }
Now switch to MainWindow.xaml, locate main Grid
tag and insert your user control there. It should look something like this:
<Grid> <local:Host /> </Grid>
Don’t forget to import your local namespace for XAML engine to see our new User Control:
xmlns:local="clr-namespace:WpfApplication1"
Add this to Window tag. Just replace WpfApplication1
with your local namespace.
Now you can build solution and run it. Windows Firewall may ask you to Allow access first time you launch application. We use sockets to send UI updates to the application when you edit Ammy files in Visual Studio. Update code is only generated in Debug
build, so when you compile in Release
, no network sockets will be created. If you want to turn UI update in Debug
build, you can use NO_AMMY_UPDATE
conditional compilation symbol.
You should see an empty window with “Hello, World!” in the left corner. Switch back to Visual Studio without closing the application and change text to “Hello from Ammy”. Save file and watch as text in your application is updated to the new one.
You can now add new user controls or windows to further develop your application. But what if you wanted MainWindow to also be Ammy file?
Using Ammy to define MainWindow
- Create WPF application and install Ammy nuget package as described in previous section
- Delete
MainWindow.xaml
file - Click Add -> New Item… and choose Ammy Window
- Call it
MainWindow.ammy
- Go to
App.xaml
and changeStartupUri="MainWindow.xaml"
toStartupUri="MainWindow.g.xaml"
- Add
TextBlock { "Hello, World!" }
toMainWindow.ammy
and start the application
Using Ammy to define both App and MainWindow
Defining App with Ammy gives you the opportunity to create global XAML styles in App.ammy
and update them in runtime to immediately see changes.
- Create WPF application and install Ammy nuget package as described in previous section
- Delete
MainWindow.xaml
file - Delete
App.xaml
- Add two Ammy files.
MainWindow.ammy
as in previous section and Ammy Application namedApp.ammy
- You should be able to run your app now. If you want to test its’ workings, add the same
TextBlock
as in previous section