How to use a templated control in main window view?
The project will build and run, but will not display the templated control on the designer or when the application is ran. Do I have something wrong? I've been following AngelSix's Avalonia Tutorial to start back at the basics and relearn what I didn't take the time to learn before, and we're at the part of using TemplatedControls and I can't get mine to show up. Thanks in advance!
2 Replies
this doesn't work either
removed the
;assembly=LoudnessMeter
part and that didn't work eitherHi @Mekasu0124, when using a templated control that is defined as a
ResourceDictionary
you need to include the resource itself in the main window view, like so:
<Window>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://LoudnessMeter.Views.TemplatedControls/LargeLabelControl.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>
<Grid>
<Grid>
<StackPanel>
<controls:LargeLabelControl />
</StackPanel>
</Grid>
</Grid>
</Window>
I hope this helps