修改WPF中MaterialDesign DatePicker的内部文本框的“鼠标悬停”颜色。

huangapple go评论72阅读模式
英文:

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

问题

You can change the DatePicker's TextBox underline and calendar icon color like this:

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

This code should change the color of both the TextBox underline and the calendar icon.

英文:

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

enter image description here

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

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?

答案1

得分: 0

你应该重写 DatePickerPrimaryHueMidBrush 以更改图标的颜色:

&lt;DatePicker materialDesign:HintAssist.Hint=&quot;开始日期&quot; Margin=&quot;0,25,0,0&quot;
            materialDesign:TextFieldAssist.UnderlineBrush=&quot;{StaticResource MainThemeColor3}&quot;&gt;
    &lt;DatePicker.Resources&gt;
        &lt;SolidColorBrush x:Key=&quot;PrimaryHueMidBrush&quot; Color=&quot;红色&quot; /&gt;
    &lt;/DatePicker.Resources&gt;
    &lt;DatePicker.CalendarStyle&gt;
        &lt;Style TargetType=&quot;Calendar&quot; BasedOn=&quot;{StaticResource MaterialDesignCalendarPortrait}&quot;&gt;
            &lt;Style.Resources&gt;
                &lt;SolidColorBrush x:Key=&quot;PrimaryHueMidBrush&quot; Color=&quot;{StaticResource secondaryBackColor1}&quot;/&gt;
                &lt;SolidColorBrush x:Key=&quot;PrimaryHueDarkBrush&quot; Color=&quot;{StaticResource secondaryBackColor2}&quot;/&gt;
            &lt;/Style.Resources&gt;
        &lt;/Style&gt;
    &lt;/DatePicker.CalendarStyle&gt;
&lt;/DatePicker&gt;
英文:

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

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

huangapple
  • 本文由 发表于 2023年7月13日 10:25:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76675513.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定