Once upon a time, in the old days, when WPF was a little new baby and people needed a tool to fiddle around with the new design language, Microsoft released a tool named XAMLPad, and things were all good: you didn't need Visual Studio to try your designs, you could learn XAML without having to start a new project and you could try as much as you wanted, the UI changed as you changed the XAML code.
Then, time has passed. WPF is old news, many new XAML platforms appeared and XAMLPad faded out and all that remained from it was an old page.
Although it was not there, the need remained: how to do quick tests on your XAML? How to do them for the new platforms, like UWP? Then, a Microsoft Engineer decided to revive this and XAML Studio was born.
XAML Studio is a UWP app that allows you to fiddle with the XAML code in UWP and even debug the bindings! You can get the app from the Windows Store and install it in your machine for free.
Once you install and open it, you will get a window like this:
The app has a tabbed interface and you can create a new page and start typing your code. When you create a new page, a new tab will open, like this one:
You can start changing things immediately and the changes will reflect on the top pane. For example, if you change the color of the first run of text to Navy, the top pane will reflect that. If you make a typing mistake, a pink box will be shown in the top pane, indicating the compilation error:
The last icon in the navigation bar is the toolbox. When you select it, you will have all available components to insert in your code. You can filter the items you want by typing in the search box at the top:
In this post, I've shown how to use the NavigationView in UWP. With XAML Studio, we don't need to use Visual Studio to test the code, we can just type it in the code window and the UI will be shown in the top pane. If you type something like:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:winui="using:Microsoft.UI.Xaml.Controls">
<winui:NavigationView >
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem Content="Main" Icon="Home" />
</winui:NavigationView.MenuItems>
<Grid Padding="40">
<TextBlock>
<Run FontSize="24" Foreground="Navy">Get Started with XAML Studio</Run><LineBreak/>
<Run> Modify this text below to see a live preview.</Run>
</TextBlock>
</Grid>
</winui:NavigationView>
</Page>
You will get something like this:
You can even use controls from Telerik or from the Microsoft Community Toolkit. For example, if you want to add a Radial Gauge to your UI, you can use something like this:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:winui="using:Microsoft.UI.Xaml.Controls"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
<winui:NavigationView >
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem Content="Main" Icon="Home" />
</winui:NavigationView.MenuItems>
<Grid Padding="40">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock>
<Run FontSize="24" Foreground="Navy">Get Started with XAML Studio</Run><LineBreak/>
<Run> Modify this text below to see a live preview.</Run>
</TextBlock>
<controls:RadialGauge Value="25" Unit="mph" NeedleBrush="Red"
TrailBrush="Green"
Grid.Row="1" Width="200"
Height="200" Foreground="Green"/>
</Grid>
</winui:NavigationView>
</Page>
One thing very interesting that can be done is to use data bindings in your code. You can create a Json Data Source or use a remote data source to bind to your data. For example, if you go to the second icon (Data Source) and add something like this:
{
'Title' : 'Using XAML Studio',
'Subtitle' : 'By Bruno Sonnino',
'GaugeValue' : 35,
'GaugeUnit' : 'km/h',
'GaugeNeedle' : 'DarkGreen'
}
You can bind to your code with something like this:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:winui="using:Microsoft.UI.Xaml.Controls"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
<winui:NavigationView >
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem Content="Main" Icon="Home" />
</winui:NavigationView.MenuItems>
<Grid Padding="40">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock>
<Run FontSize="24" Foreground="Navy" Text="{Binding Title}"/><LineBreak/>
<Run Text="{Binding Subtitle}"/>
</TextBlock>
<controls:RadialGauge Value="{Binding GaugeValue}" Unit="{Binding GaugeUnit}"
NeedleBrush="{Binding GaugeNeedle}"
TrailBrush="Green"
Grid.Row="1" Width="200"
Height="200" Foreground="Green"/>
</Grid>
</winui:NavigationView>
</Page>
You can also bind to a remote data source, using an URL to a JSON service. For example, we can bind to the European Currency Exchange service to get the quotes of the currencies against the Euro. Just go to the Data Source option and select the Remote Data Source and enter this URL:
https://api.exchangeratesapi.io/latest
Then you can show the values for the currencies in a DataGrid with this code:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">
<Grid Padding="40">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="0,10">
<TextBlock Text="Base" Margin="5,0"/>
<TextBlock Text="{Binding base}" Margin="5,0"/>
<TextBlock Text="Date" Margin="5,0"/>
<TextBlock Text="{Binding date}" Margin="5,0"/>
</StackPanel>
<controls:DataGrid ItemsSource="{Binding rates}" Grid.Row="1"/>
</Grid>
</Page>
One nice feature is that you can debug your bindings. In the code window, you can notice a green background in the bindings. If you hover the mouse in the binding, it will show you the current value:
When you go to the third menu item (Debug Bindings), you can even get more information, like the history for the binding or the values for all bindings at once:
Conclusions
As you can see XAML Studio has a lot of features for who wants to try some XAML code or even learn XAML. You don't need to fire Visual Studio to test your XAML code and see what happens if you change something. It's still a work in progress and has a lot of room for improvement, but with no doubt it's a very nice tool to have in your toolbox.
I played with the tool and this is the simple tool we need to fiddle around and learn how to use xaml. However I wanted to use it for Xamarin Xaml and it does not work. Ideally you use Xaml studio to test and tune XAML and copy and paste it into VS.
Pity as this is could be a very useful program.
Hello All,
I know that an old post but is there any solution to get this application when Microsoft Store is forbidden in my company ?
Thanks in advance.
The only way I know it is to use the appx file to install it directly, but AFAIK, there is no appx for XAML Studio