我想使用Foreground
中的TextBox
更改Silverlight3
中VisualState
的{{1}}。下面的代码是我到目前为止所尝试的。但它没有用。请指导我。
Resources
以上是<TextBox x:Name="EmailTextBox" Text="{Binding UserName, Mode=TwoWay}"
Grid.Row="0" Grid.Column="1" Style="{StaticResource TextBoxEmailStyle}"/>
的引用Style
:
TextBox
答案 0 :(得分:1)
您的Storyboard.TargetProperty
不正确,您需要提供默认状态&#34; Unfocused&#34;没有Foreground
更改(或者你永远不能回到&#34;正常&#34;)。
<VisualState x:Name="Unfocused"/>
<VisualState x:Name="Focused">
<Storyboard>
<ColorAnimation Duration="0" To="#00000000"
Storyboard.TargetName="ContentElement"
Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)"/>
</Storyboard>
</VisualState>
顺便说一句:颜色#00000000将不可见,也许您想将其更改为#FF000000
确保Foreground实际上默认设置为SolidColorBrush
实例:
<ScrollViewer x:Name="ContentElement" Foreground="White" ... />
通常,当想要更改控件的Template
时,您将包含为此控件定义的所有VisualStates
。因此,尝试添加这些状态,可能会导致VisualState
更新方法退出,因为未定义the other TextBox states。
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">...</VisualState>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Disabled"/>
<VisualState x:Name="ReadOnly"/>
</VisualStateGroup>
<VisualStateGroup x:Name="ValidationStates">
<VisualState x:Name="Valid"/>
<VisualState x:Name="InvalidFocused"/>
<VisualState x:Name="InvalidUnfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
编辑好的,所以你说这是在SL4中工作但在SL3中没有?好吧,看看features added with SL4,看看你是否找到了解释为什么模板在SL3中无法正常工作但是在SL4中有效的原因。