如何将DatePicker的前景设置为禁用状态?
我试过设置样式res:
<SolidColorBrush x:Key="DatePickerForegroundThemeBrush" Color="#444444" />
和
dpDate.IsEnabled = false;
dpDate.Foreground = new SolidColorBrush(Colors.Black);
但它仍然透明。
答案 0 :(得分:2)
您需要修改DatePicker控件的模板,以便在处于禁用可视状态时更改其行为;实际上,DatePicker中有一个按钮,您需要更改该按钮的行为。
XAML:
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground"
Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource ButtonDisabledForegroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush"
Storyboard.TargetName="Border">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource ButtonDisabledBorderThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background"
Storyboard.TargetName="Border">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource ButtonDisabledBackgroundThemeBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
有关自定义控件模板的更详细示例,请结帐Quickstart: Control templates (XAML)。