<UserControl x:Class="WpfApplication6.LeftButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style x:Key="ListLeftButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Rectangle x:Name="rectangle">
<Rectangle.Fill>
<ImageBrush ImageSource="skin/01228[46x62x8BPP].png"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Fill" TargetName="rectangle">
<Setter.Value>
<ImageBrush ImageSource="skin/01227[46x62x8BPP].png"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Fill" TargetName="rectangle">
<Setter.Value>
<ImageBrush ImageSource="skin/01226[46x62x8BPP].png"></ImageBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<StackPanel>
<Button Style="{StaticResource ListLeftButton}" Width="50" Height="60"/>
<Button Style="{StaticResource ListLeftButton}" Width="50" Height="60"/>
<Button Style="{StaticResource ListLeftButton}" Width="50" Height="60"/>
<Button Style="{StaticResource ListLeftButton}" Width="50" Height="60"/>
<Button Style="{StaticResource ListLeftButton}" Width="50" Height="60"/>
<Button Style="{StaticResource ListLeftButton}" Width="50" Height="60"/>
</StackPanel>
</UserControl>
我利用模板自定義了按鈕,這些按鈕的樣式都相同只是背景圖片不一樣,但我只會在模板中定義一張,要不同的按鈕對應不同的圖片應該怎麼做吶?求解答,多謝
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<br>
<Setter Property="Template"><br>
<Setter.Value><br>
<ControlTemplate TargetType="{x:Type Button}"><br>
<Grid><br>
<Rectangle x:Name="rectangle"><br>
<Rectangle.Fill><br>
<ImageBrush ImageSource="skin/01228[46x62x8BPP].png"/><br>
</Rectangle.Fill><br>
</Rectangle><br>
</Grid><br>
<ControlTemplate.Triggers><br>
<Trigger Property="IsFocused" Value="True"><br>
<Setter Property="Fill" TargetName="rectangle"><br>
<Setter.Value><br>
<ImageBrush ImageSource="skin/01227[46x62x8BPP].png"/><br>
</Setter.Value><br>
</Setter><br>
</Trigger><br>
<Trigger Property="IsDefaulted" Value="True"/><br>
<Trigger Property="IsMouseOver" Value="True"/><br>
<Trigger Property="IsPressed" Value="True"><br>
<Setter Property="Fill" TargetName="rectangle"><br>
<Setter.Value><br>
<ImageBrush ImageSource="skin/01226[46x62x8BPP].png"></ImageBrush><br>
</Setter.Value><br>
</Setter><br>
</Trigger><br>
<Trigger Property="IsEnabled" Value="False"/><br>
</ControlTemplate.Triggers><br>
</ControlTemplate><br>
</Setter.Value><br>
</Setter><br>
效果如圖
我想讓每張圖片都不一樣怎麼做