AvaloniaCommunity/Material.Avalonia

ColorZone causes crashes when using MaterialThemeBase

leoaviana opened this issue · 0 comments

I am trying to use a NavigationDrawer using the example provided at Material.Demo, but following the wiki, the recommended practice to modify themes with code is to use MaterialThemeBase in the App.axaml file, so I did that.

App.axaml

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:themes="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
            xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
             xmlns:local="using:myApp"
             x:Class="myApp.App">
    <Application.DataTemplates>
        <local:ViewLocator/>
    </Application.DataTemplates>

	<Application.Styles>
		<!--themes:MaterialTheme BaseTheme="Dark" PrimaryColor="DeepPurple" SecondaryColor="DeepPurple" /> -->
		<themes:MaterialThemeBase/> 
		<materialIcons:MaterialIconStyles />
		<Style Selector=":is(TemplatedControl)">
			<Setter Property="FontSize" Value="13"/>
		</Style>
	</Application.Styles>

</Application>

I set everything correctly also on App.axaml.cs where I need to create a theme on OnFrameworkInitializationCompleted, but that is not the issue, I can load the app correctly without using ColorZone, but when I add a ColorZone the application crashes immediately after startup.

<styles:SnackbarHost HostName="Root">
 <styles:NavigationDrawer Name="LeftDrawer"
                           LeftDrawerOpened="{Binding ElementName=NavDrawerSwitch, Path=IsChecked, Mode=TwoWay}">
  <styles:NavigationDrawer.LeftDrawerContent>
	  <ScrollViewer>
		  <StackPanel>
			  <styles:ColorZone Mode="Accent" Height="180">
				  <StackPanel>
					  <Image Width="120" Height="120" HorizontalAlignment="Center" VerticalAlignment="Top"
							 Source="/Resources/myapp.ico" Margin="0,0,0,-8" />
				  </StackPanel>
			  </styles:ColorZone>
...

When I was messing around to find out what was causing the issue, I got this exception in the design window and if I remove the ColorZone it disappears:

System.Xaml.XamlException: Cannot locate T in Avalonia application styles. Be sure that you include MaterialTheme in your App.xaml in Application.Styles section

Is this an expected behavior? Do I have to use MaterialTheme in App.xaml to be able to use ColorZones? Thank you in advance.