我想为文本框制作一个简单的样式。我想保留关于 标准文本框外观和感觉的所有内容,除了一个项目。文本框的样式Silverlight
OnFocus on希望能够更改文本框的边框颜色。
我写了下面的内容,它确实有效。然而,一切都重新调整,我不得不 宣布高度,非聚焦边界的外观和感觉也不同。我怎样才能创建模板来仅仅实现onfocus状态。
<Style x:Key="TextBoxStyle" TargetType="TextBox">
<Setter Property="BorderBrush" Value="Gold" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid Height="{TemplateBinding Height}"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver" />
<VisualState x:Name="Pressed" />
<VisualState x:Name="Disabled" />
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused">
<Storyboard>
<ColorAnimation Storyboard.TargetName="brd"
Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
Duration="0"
To="Red" />
</Storyboard>
</VisualState>
<VisualState x:Name="Unfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="brd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
CornerRadius="2">
<ContentPresenter x:Name="contentPresenter" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您是否尝试过BasedOn属性? – SirDemon 2010-07-28 14:08:20