Search code examples
c#wpfdatepickertextboxmaterial-design

Change the inner textbox 'mouse over' color of the MaterialDesign DatePicker in WPF


Can i change DatePicker's TextBox underline and calender icon color?
like below :

enter image description here

                                    <DatePicker materialDesign:HintAssist.Hint="Start Date" Margin="0,25,0,0"
                                                materialDesign:TextFieldAssist.UnderlineBrush="{StaticResource MainThemeColor3}">
                                        <DatePicker.CalendarStyle>
                                            <Style TargetType="Calendar" BasedOn="{StaticResource MaterialDesignCalendarPortrait}">
                                                <Style.Resources>
                                                    <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource secondaryBackColor1}"/>
                                                    <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource secondaryBackColor2}"/>
                                                </Style.Resources>
                                            </Style>
                                        </DatePicker.CalendarStyle>
                                    </DatePicker>

I tried like this but this can only change the color after clicked and focused one.

enter image description here

You can see that the icon's color still hasn't changed.

How can i change it?


Solution

  • You should override the PrimaryHueMidBrush for the DatePicker to change the colour of the icon:

    <DatePicker materialDesign:HintAssist.Hint="Start Date" Margin="0,25,0,0"
                materialDesign:TextFieldAssist.UnderlineBrush="{StaticResource MainThemeColor3}">
        <DatePicker.Resources>
            <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="Red" />
        </DatePicker.Resources>
        <DatePicker.CalendarStyle>
            <Style TargetType="Calendar" BasedOn="{StaticResource MaterialDesignCalendarPortrait}">
                <Style.Resources>
                    <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource secondaryBackColor1}"/>
                    <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource secondaryBackColor2}"/>
                </Style.Resources>
            </Style>
        </DatePicker.CalendarStyle>
    </DatePicker>