以下是我的一個WPF的DatePicker造型:DatePickerTextBox白色背景上禁用
<Style TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Padding" Value="1" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePickerTextBox}">
<Border
x:Name="brdBackground"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer
x:Name="PART_ContentHost"
Foreground="{TemplateBinding Foreground}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="brdBackground" Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type DatePicker}">
<Setter Property="Margin" Value="6" />
<Setter Property="Background" Value="#858ca0" />
<Setter Property="BorderBrush" Value="#303e66" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
當DatePicker的啓用它看起來正是我希望它:
http://imageshack.us/photo/my-images/819/enabled.jpg/
然而,當禁用DatePicker時,其中包含的DatePickerTextBox的背景變爲白色:
http://imageshack.us/photo/my-images/832/disableda.jpg/
我不想讓DatePickerTextBox在DatePicker變爲禁用狀態時進行更改。當它的IsEnabled屬性設置爲false時,DatePicker的不透明度設置爲0.5,這就是我想要發生的事情。鑑於我正在使用控件模板,並且我重寫了DatePickerTextBox的默認樣式,我開始認爲它實際上並不是DatePickerTextBox被設置爲白色,而是其他東西。任何幫助將不勝感激
或者更改'To'值較低,如0.1 – 2013-09-18 15:06:26