karn
karn

Reputation: 51

wpf button with foreground and background as image

In my wpf application I have a button. I want the button like to be background have an image and forground also have the image. How to do this?

Thanks in advance, Karn

Upvotes: 2

Views: 3985

Answers (2)

Fredrik Hedblad
Fredrik Hedblad

Reputation: 84657

Not sure I understand what you want here, but here's two examples

Two different Images for foreground and background

<Button Content="Button" FontSize="50" Margin="0,0,263,155">
    <Button.Background>
        <ImageBrush ImageSource="C:\Time.png"/>
    </Button.Background>
    <Button.Foreground>
        <ImageBrush ImageSource="C:\C1.png"/>
    </Button.Foreground>
</Button>

alt text

Same Image as Foreground and Background

<Button Content="Button"
        FontSize="50"
        Foreground="{Binding RelativeSource={RelativeSource self}, Path=Background}">
    <Button.Background>
        <ImageBrush ImageSource="C:\Time.png"/>
    </Button.Background>
</Button>

alt text

Upvotes: 6

Dan J
Dan J

Reputation: 16708

In general, you need to override the button's default appearance using a Style and / or a ControlTemplate.

For examples, you may want to see:

Feel free to provide more specifics or some code if you're having trouble, and we'll be able to help further.

Upvotes: 1

Related Questions