user937036
user937036

Reputation: 391

WPF: define image background in Style

How do I add a URI image to be used as the background for this style? Is it possible?
Using URI like: "/WpfAPP10;component/Interface.png"

<Style x:Key="mega" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button"  >
<Setter Property="Margin" Value="4"/>
</Style>

Upvotes: 0

Views: 342

Answers (2)

user937036
user937036

Reputation: 391

This is what has worked.

<Setter Property="Background">
                <Setter.Value>
                    <ImageBrush ImageSource="/uif\yellow.png"/>
                </Setter.Value>
            </Setter>

Upvotes: 1

pushpraj
pushpraj

Reputation: 13679

  • add image to your project
  • set build action to "Resource"

use as

<Style x:Key="mega" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button"  >
    <Setter Property="Margin" Value="4"/>
    <Setter Property="Background" Value="/WpfAPP10;component/Interface.png"/>
</Style>

or

<Setter Property="Background" Value="Interface.png"/>

or

<Setter Property="Background" Value="pack://application:,,,/WpfAPP10;component/Interface.png""/>

this will set the desired image to the background

Upvotes: 1

Related Questions