嗯,我是WPF的新手,这是我第一次尝试改变WPF控件的样式。感谢Expression Blend,一切都比预期的更好,直到我做出这种风格。ColorAnimationUsingKeyFrames改变画笔
<Style TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PART_ContentHost">
<EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
</DoubleAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="Background">
<EasingColorKeyFrame KeyTime="0" Value="Red"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="Background">
<EasingColorKeyFrame KeyTime="0" Value="Yellow"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="ReadOnly"/>
<VisualState x:Name="MouseOver"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="Background" Fill="{StaticResource ControlBackgroundBrush}" Stroke="{StaticResource NormalBrush}" RadiusX="2" RadiusY="2"/>
<ScrollViewer x:Name="PART_ContentHost" Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" FontFamily="{TemplateBinding FontFamily}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
</Style>
这两个刷在这里:
<Color x:Key="MainColor">#FF595959</Color>
<Color x:Key="ControlBackgroundColor">#FF333333</Color>
<SolidColorBrush x:Key="NormalBrush" Color="{DynamicResource MainColor}"/>
<SolidColorBrush x:Key="ControlBackgroundBrush" Color="{StaticResource ControlBackgroundColor}" />
那么,什么是问题。禁用文本框应该改变文本框的边框颜色和背景,但它也会改变所有使用的颜色NormalBrush
。我想只有几个通用的控件让主题容易修改。还有一件事我使用他们Usualy在其他样式作为StaticResource。您的建议和帮助将受到高度赞赏。
正在发生,因为你是动画(逐步改变静态或共享资源)致毒。如果您只需要影响本地元素,则需要创建本地模板。对于你想要完成的任务,我认为'VisualState'方法是过分的,为了记录。 “ControlTemplate.Trigger”可以轻松触发本地彩色动画。 – XamlZealot
另一种可能的方法(尽管我不确定这会对其他应用程序组件产生什么样的其他影响)是使画笔不共享: ' ' –
XamlZealot