我有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