【发布时间】:2014-07-02 16:21:11
【问题描述】:
我对 Xaml/WPF 知之甚少。我正在尝试在 Windows 8 Metro 应用程序中为 Button 设计一个自定义 Style,它具有洋红色背景,按下时具有蓝色背景。我知道我需要使用 VisualStateManager,但我可以'在网上找不到任何对对该主题知之甚少的人有意义的东西。有很多假设的知识。到目前为止,这是我所得到的:
<Style x:Name="test" TargetType="Button">
<Setter Property="Background" Value="Magenta"/>
<Setter Property="Content" Value="Test style" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<Storyboard>
<turn the background blue>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
此代码可能非常错误,但正如我所说,我一直在尝试将我不理解的信息修补在一起以创建结果。
感谢您的宝贵时间
【问题讨论】:
-
我从研究所有控件的默认样式模板开始。对于此示例,我建议采用默认的 Button 控件样式模板并根据您的目的对其进行编辑,而不是在最初几次尝试从头开始。正如 John 指出的那样,Blend 非常适合这类工作。
标签: wpf xaml windows-8 microsoft-metro