Hello Everybody,

I have run into a bit of a trouble here
I wish to set the background image of a button
I have written this XAML

<Button.Background>
                <ImageBrush ImageSource="/UIDesign;component/Images/Settings.png" />
      </Button.Background>

but when i run the application and hover the mouse over the button, the background goes away and default button background comes in. I wish it to stay even when i hover the mouse

Am i missing something really obvious?
How do i do this?

Please help

VV1

You need to modify the control template to override the default mouseover and click triggers. Here is a sample:

<Style x:Key="BorderlessButton" TargetType="{x:Type Button}">
            <Setter Property="Padding" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border Name="border" Background="{TemplateBinding Background}">
                            <ContentPresenter Name="content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              Margin="{TemplateBinding Padding}" 
                                              RecognizesAccessKey="True" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="content" Property="RenderTransform" >
                                    <Setter.Value>
                                        <ScaleTransform ScaleX="1.1" ScaleY="1.1" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" >
                                            <GradientStop Color="LightGray" Offset="0.35"/>
                                            <GradientStop Color="Gray" Offset="0.95"/>
                                            <GradientStop Color="LightGray" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="content" Property="RenderTransform" >
                                    <Setter.Value>
                                        <ScaleTransform ScaleX=".95" ScaleY=".95" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsFocused" Value="True">
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.