【发布时间】:2014-10-30 12:58:58
【问题描述】:
我想使用Resources 中的VisualState 更改Silverlight3 中的TextBox 的Foreground。下面的代码是我迄今为止尝试过的。但它没有用。请指导我。
<TextBox x:Name="EmailTextBox" Text="{Binding UserName, Mode=TwoWay}"
Grid.Row="0" Grid.Column="1" Style="{StaticResource TextBoxEmailStyle}"/>
这里是上面TextBox 的引用Style:
<Style x:Key="TextBoxEmailStyle" TargetType="TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid x:Name="RootElement">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="FocusStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Focused">
<Storyboard>
<ColorAnimation
Duration="0" To="#00000000"
Storyboard.TargetName="ContentElement"
Storyboard.TargetProperty="(ContentElement.Foreground).
(SolidColorBrush.Color)"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Opacity="1">
<Grid>
<Border x:Name="ReadOnlyVisualElement"
Background="#5EC9C9C9"
Opacity="0"/>
<Border x:Name="MouseOverBorder"
BorderBrush="Transparent"
BorderThickness="1">
<StackPanel Orientation="Horizontal">
<Image
Width="40"
Source="/Images/sign_in_email.png"
Margin="5,5,5,5"/>
<ScrollViewer x:Name="ContentElement"
BorderThickness="0"
IsTabStop="False"
Padding="{TemplateBinding Padding}"
VerticalAlignment="Center"
Margin="4"/>
</StackPanel>
</Border>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
【问题讨论】:
标签: wpf xaml silverlight windows-phone-7