[英]TextBox , different ControlTemplate + IsEnabled
I have added a style
to a textbox
, where in I modify the ControlTemplate
of the textBox
. 我向textbox
添加了style
,在其中修改了textBox
的ControlTemplate
。 I end up having a different control template
for the textbox
. 我最终为textbox
使用了另一个control template
。 But I have a problem. 但是我有一个问题。 When I set the IsEnabled
property to false, the normal textbox, is just greyed
out. 当我将IsEnabled
属性设置为false时,普通的文本框只是greyed
为greyed
。 But the one with different control template, still remains white
. 但是具有不同控制模板的那个仍然保持white
。
Is there something specific I need to add as a part of control template
, in order to obtain the default behavior? 为了获得默认行为,我需要添加一些特定的东西作为control template
的一部分吗?
thanks Sandeep 谢谢桑迪普
Update -> Added the control template. 更新->添加了控件模板。
<ControlTemplate TargetType="{x:Type commonControls:DerivedTextBox}">
<Border Name="Border"
CornerRadius="2"
Padding="2"
BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="{DynamicResource ControlLightColor}" />
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
</Border.BorderBrush>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0"
Value="{DynamicResource ControlLightColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ReadOnly">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0"
Value="{StaticResource DisabledControlDarkColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="MouseOver" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer Margin="0"
x:Name="PART_ContentHost" />
</Border>
</ControlTemplate>
You have replaced the default XAML that makes the TextBox
'grayed out' when IsEnabled
is set to False
. 当IsEnabled
设置为False
时,您已替换了默认的XAML,该默认XAML使TextBox
变灰。 If you want to replace this functionaluity, you will need to copy that part of the original ControlTemplate
, which you can find at the TextBox Styles and Templates
page on MSDN. 如果要替换此功能,则需要复制原始ControlTemplate
该部分,您可以在MSDN上的“ TextBox Styles and Templates
页面上找到该TextBox Styles and Templates
。
In the default ControlTemplate
, you will see a VisualState
with the name Disabled
... that is what you need, but you may as well copy most of the VisualState
s from there. 在默认的ControlTemplate
,您将看到一个名称为Disabled
...的VisualState
,这是您所需要的,但您也可以从那里复制大多数VisualState
。
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0"
Value="{StaticResource DisabledControlLightColor}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.