Setting WPF control background image using styles?

Posted by aviv on Stack Overflow See other posts from Stack Overflow or by aviv
Published on 2010-05-13T14:14:17Z Indexed on 2010/05/13 14:34 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

Hi,

I have a set of buttons inside a stack panel. I want them all to have a background image. How can i do it using styles? since i don't want to set manually the Background image for each button.

Here is a code snippet:

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

Thanks.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about style