Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Wpf background for button disappeared on mouseover - cannot override the style

$
0
0

I have a button in wpf with a background image
I try to override the style to avoid picture disapeared onmouseover.

i try to do this here:

<Window x:Class="WPFTEst.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:my="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"><Window.Resources><ControlTemplate x:Key="TemplateTest" TargetType="ButtonBase"><my:ButtonChrome Background="{TemplateBinding Control.Background}"
                             BorderBrush="{TemplateBinding Control.BorderBrush}"
                             Name="Chrome" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" RenderPressed="{TemplateBinding ButtonBase.IsPressed}" SnapsToDevicePixels="True"><ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                  ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                                  ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                  HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                  Margin="{TemplateBinding Control.Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" /></my:ButtonChrome><ControlTemplate.Triggers><Trigger Property="ToggleButton.IsMouseOver" Value="True"><Setter Property="Background" TargetName="Chrome" Value="{Binding Path=Background, RelativeSource={RelativeSource}}" /></Trigger><Trigger Property="ToggleButton.IsChecked" Value="True"><Setter Property="my:ButtonChrome.RenderPressed" TargetName="Chrome" Value="True" /></Trigger><Trigger Property="UIElement.IsEnabled" Value="False"><Setter Property="Control.Foreground" Value="#FFADADAD" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Window.Resources><Grid><Button Content="Button" Height="128" HorizontalAlignment="Left" Margin="130,88,0,0" Name="button1" VerticalAlignment="Top" Width="272" Template="{StaticResource TemplateTest}"><Button.Background><ImageBrush ImageSource="/WPFTEst;component/Images/Tulips.jpg" /></Button.Background><Button.BorderBrush><ImageBrush ImageSource="/WPFTEst;component/Images/Tulips.jpg" /></Button.BorderBrush></Button></Grid></Window>

where is the mouseover trigger ?

i took the template from base template "extract value to resource"

thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>