解决方案
20
<Style TargetType="{x:Type Button}"> <Setter Property ="GroupName" Value="SelectTicket"/> <Setter Property="Height" Value="40"></Setter> <Setter Property="Width" Value="60"></Setter> <Setter Property="FontSize" Value="18"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="ContentContainer" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Center" HorizontalAlignment="Stretch" CornerRadius="2"> <TextBlock Text="{TemplateBinding Content}" Foreground="White" VerticalAlignment="Center" TextAlignment="Center" HorizontalAlignment="Center"/> <Border.Background> <ImageBrush ImageSource="/Images/Background.png"/> </Border.Background> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" TargetName="ContentContainer"> <Setter.Value> <ImageBrush ImageSource="/Images/PressBg.png"/> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Background.png 与 PressBg.png 都是作为 内容 嵌入到 Image文件夹下
10
<Setter Property =”GroupName” Value=”SelectTicket”/>
把这个去掉。
把这个去掉。
10
1:设置 style的Key值 也就是 x:Key=”” 具体一个名字,然后在Button 的xaml 上使用staticresource引用。具体去搜索用法
2:Property 设置成其它事件,例如IsFocused 等, 了解 WPF 触发器
2:Property 设置成其它事件,例如IsFocused 等, 了解 WPF 触发器