【发布时间】:2014-09-17 08:24:03
【问题描述】:
样式在资源中:
<Style x:Key="RoundCornerSmart" TargetType="{x:Type vk:SmartButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type vk:SmartButton}">
<Border CornerRadius="8" BorderBrush="#006AB6" BorderThickness="1" Name="border" Background="{TemplateBinding Background}">
<Grid x:Name="grid" >
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"></ContentPresenter>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="border">
<Setter.Value>
LightGray
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Command" Value="{Binding KeyCommand}" />
<Setter Property="FontSize" Value="8"/>
<Setter Property="Height" Value="52"/>
<Setter Property="Width" Value="52"/>
<Setter Property="Margin" Value="10"></Setter>
<Setter Property="Foreground" Value="Black"></Setter>
<Setter Property="Background" Value="White"></Setter>
<Setter Property="BorderBrush" Value="Black"></Setter>
</Style>
我有一个名为 SmartButton 的类,它扩展了 Button 类。
<vk:SmartButton Content="Some content" Grid.Column="3" Style="{DynamicResource RoundCornerSmart}" />
对于这个按钮,当我按下它时,背景保持不变(白色),我需要它是浅灰色。我做错了什么?
【问题讨论】: