我在堆栈面板中有一组按钮。我希望他们所有人都有背景图片。我该如何使用样式?因为我不想为每个按钮手动设置背景图像。
这是一个代码片段:
<StackPanel Orientation="Horizontal" Height="100px" VerticalAlignment="Top">
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="2,4" />
</Style>
</StackPanel.Resources>
<Button Width="127px" Height="79px" VerticalAlignment="Bottom">
<Button.Background>
<ImageBrush ImageSource="images/Tab.png" />
</Button.Background>
</Button>
<Button>A</Button>
<Button>R</Button>
<Button>S</Button>
</StackPanel>
谢谢。
最佳答案
好了,您为样式中的Background
属性指定了一个setter,并将其值设置为ImageBrush
。
<StackPanel Orientation="Horizontal" Height="100px" VerticalAlignment="Top">
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="2,4"/>
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="images/Tab.png"/>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<Button Width="127px" Height="79px" VerticalAlignment="Bottom"/>
<Button>A</Button>
<Button>R</Button>
<Button>S</Button>
</StackPanel>
关于wpf - 使用样式设置WPF控件背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2827473/