我正在研究WPF應用程序。我有一個資源字典,我在其中爲ToolTip和Button編寫了自定義樣式。事實上,我做了兩種風格的按鈕。 其中之一,包括一個圖像顯示在buttoon內容的左側。動態更改樣式的屬性
<Style x:Key="ButtonImageStyle" TargetType="{x:Type Button}">
........
<TextBlock Margin="5.25,2.417,5.583,5.25" Foreground = White />
<Image x:Name="ButtonImage" Source="/MyProject;component/Images/icoMainMenu01.png" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="-100,0,0,0" Width="16" Height="16"/>
.... </Style
現在,在MainWindow.xaml我有以下幾點:
<Button Style="{DynamicResource ButtonImageStyle}" x:Name="JustButton" Click="JustButton_Click" Height="50" ToolTip="Press for 1" Content="1" Margin="310,282,400,238" />
我希望能夠改變這種形象。我會有8個按鈕,我希望每個按鈕都有不同的圖像。 你們有什麼想法嗎? 謝謝!
哇。感謝你的回答。問題在於,我是WPF的新成員_kinda_。你能提供一個簡單的例子來解決我的問題嗎?這會讓我的生活變得更容易 –
@MihaiuAdrian:好吧,可能需要幾分鐘... –
謝謝。我回到別的東西,直到你回答。非常感謝你! :) –