我想为我的自定义按钮模板提供模板属性,其中包含影响图像内容的不同选项。如何动态设置模板属性选项
I.e.
- 关闭
- 最大化
- 恢复
- 最小化
所以当控制的用户想要设置按钮最大化的类型,他们把它挑出来一降下来在属性检查器中,嵌入在按钮中的图像控件的源变为“{DynamicResource MaximiseGlyph}”。
我怎样才能让用户选择的按钮,然后这也将选择适当的图像控制源的模板?
这里是我的按钮模板的当前基本代码:
<Style x:Key="WindowControlButton" TargetType="{x:Type Button}">
<Style.Resources>
<BitmapImage x:Key="RestoreGlyph" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="\Restore.png"/>
<BitmapImage x:Key="MaximiseGlyph" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="\Maximise.png"/>
<BitmapImage x:Key="CloseGlyph" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="\Close.png"/>
<BitmapImage x:Key="MinimiseGlyph" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="\Minimise.png"/>
</Style.Resources>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Ellipse Fill="Black" Opacity="0.7">
<Ellipse.Stroke>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FFB8B8B8" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Stroke>
</Ellipse>
<Image Source="{DynamicResource RestoreGlyph}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
你能澄清你的问题是什么? – kaj 2012-03-03 21:29:59
那么如何将模板属性设置为四个值之一,然后设置用户选择的值将按钮内图像的源属性更改为四个不同值之一 – Kian 2012-03-03 21:33:28