wpfmaterial-design-in-xaml

using StaticResource in hijacked Style causes Crash


I am using the materialDesign in xaml Toolkit. I am trying to Style the TimePicker to match my theme. Unfortunately the Timepicker has no way to set the Hint Background so I need to hijack the Style and set the Background this way. If I do it like this:

<materialDesign:TimePicker.Resources>
    <SolidColorBrush x:Key="MaterialDesignPaper">#3c3c3c</SolidColorBrush>
    <Style x:Key="MaterialDesignTimePickerTextBox" TargetType="{x:Type materialDesign:TimePickerTextBox}" BasedOn="{StaticResource MaterialDesignTimePickerTextBox}">
        <Setter Property="materialDesign:HintAssist.Background" Value="{DynamicResource MaterialDesignPaper}" />
    </Style>
</materialDesign:TimePicker.Resources>

The code works like it should. But as soon as I change it to this:

<materialDesign:TimePicker.Resources>
    <SolidColorBrush x:Key="MaterialDesignPaper" Color="{StaticResource ThemedBackground}"/>
    <Style x:Key="MaterialDesignTimePickerTextBox" TargetType="{x:Type materialDesign:TimePickerTextBox}" BasedOn="{StaticResource MaterialDesignTimePickerTextBox}">
        <Setter Property="materialDesign:HintAssist.Background" Value="{DynamicResource MaterialDesignPaper}" />
    </Style>
</materialDesign:TimePicker.Resources>

I get the following error when loading the View Set property 'System.Windows.Media.SolidColorBrush.Color' threw an exception. '#FF3C3C3C' is not a valid value for property 'Color'. Why does this happen and how would I be able to fix it?


Solution

  • ThemedBackground is a apparently not a Color but probably a Brush. In this case, you can try this:

    <SolidColorBrush x:Key="MaterialDesignPaper" Color="{Binding Color,
        Source={StaticResource ThemedBackground}}"/>
    

    It should work assuming the ThemedBackground resource is in scope.