Home > Software design >  How to preview XAML of ControlTemplate design in Visual Studio for WPF?
How to preview XAML of ControlTemplate design in Visual Studio for WPF?

Time:04-21

When designing XAML for WPF application, Visual Studio shows a generated preview design next to the XAML code editor.

However, the 'design' panel doesn't show the preview if the XAML code is in the 'Template' node, for example, ControlTemplate.

<ControlTemplate TargetType="{x:Type ListViewItem}">
...
<TextBlock Text="{Binding ListTitle}" /> <!-- IDE doesn't initially provide how this element will look like -->
...
</ControlTemplate>

There are a bunch of things inside such a ControlTemplate node, yet I have to code XAML without any preview, just relying on my estimation. Then, run the application each time to see how these XAML codes actually are being designed.

Is there a way to 'preview' the design of XAML inside ControlTemplate node?

CodePudding user response:

For this problem, you can use XAML Hot Reload, so you run your application, change and save your xaml code and see the changes simultaneously.

To enable XAML Hot Reload, go to Tools -> Options -> Debugging -> XAML Hot Reload -> Enable XAML Hot Reload in Visual Studio 2022. In Visual Studio 2019, it's almost the same, I believe it's in Tools -> Options -> Debugging -> Hot Reload. More detail on XAML Hot Reload here.

  • Related