【发布时间】:2011-09-24 15:49:26
【问题描述】:
我正在开发一个 WPF 应用程序。我有一个资源字典,我在其中为工具提示和按钮编写了自定义样式。实际上,对于按钮,我制作了两种样式。 其中之一,包括一个图像出现在按钮内容的左侧。
<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 个按钮,我希望每个按钮都有与之关联的不同图像。 你们有什么想法吗? 谢谢!
【问题讨论】: