Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ColorZone causes crashes when using MaterialThemeBase #312

Closed
leoaviana opened this issue Nov 2, 2023 · 0 comments
Closed

ColorZone causes crashes when using MaterialThemeBase #312

leoaviana opened this issue Nov 2, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@leoaviana
Copy link

leoaviana commented Nov 2, 2023

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.

@SKProCH SKProCH added the bug Something isn't working label Nov 2, 2023
@SKProCH SKProCH closed this as completed in d41f04b Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants