I am learning C # and XAML for building Windows applications. I wanted to create a button with an image as a background. But when you hover over the button, the background of the button should change to another "highlighted" image. I tried adding background images to Resource.resx. I had to create a custom button using xaml styles to get rid of the effect of highlighting the default wpf button.
I created a custom button from some code that I found on SO. Code (in the new resource dictionary):
<Style x:Key="StartMenuButtons" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="0"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="WHAT GOES HERE" TargetName="border"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
, , , .resx ? ( , ). SO, , , , . , .
:
XAML?
, ?
, , . "" .
:
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/Simon;component/Resources/btn_bg_hover.jpg" />
</Setter.Value>
</Setter>
</Trigger>
Simon
Simon
Resources
all the images
Fonts
bin
obj
Properties
, :
<Style x:Key="StartMenuButtons" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="0"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="border">
<Setter.Value>
<ImageBrush ImageSource="Resources/btn_bg_hover.jpg" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
"" , . "" visual studio, "" "".
dbaseman