Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading