我有WPF窗体,其中有许多按钮具有相同的代码。所有按钮的外观必须是相同的 例如,代码为这些按钮WPF按钮样式
<Button x:Name="btnAddRelative" Width="120" Click="btnAddRelative_Click" >
<Button.Content>
<StackPanel Orientation="Horizontal">
<Image Height="26" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage UriSource="images/add.png" />
</Image.Source>
</Image>
<TextBlock Text=" Add Relative" Height="20" VerticalAlignment="Center"/>
</StackPanel>
</Button.Content>
</Button>
如何创建一种风格,并用它为我所有的按钮之一。所有的按钮都有相同的PNG图像,只有它们的文字不同。我怎样才能做到这一点。 我试图在资源与节Style对象做到这一点:
<UserControl.Resources>
<Style TargetType="Button" x:Key="AddStyle">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal">
<Image Height="26" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage UriSource="images/add.png" />
</Image.Source>
</Image>
<TextBlock Text=" " Height="20" VerticalAlignment="Center"/>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
但这码不起作用。任何人都可以知道我该怎么做?
非常感谢。伟大的员工。它工作,因为我想!!!! – Polaris 2010-04-07 12:43:49