1

I have a Stackpanel with a Image in it. The Image is partly transperent. So i want the Background to be Red, when the mouse is not over (which works). But wen the mouse is over it should turn into green. But it doesn't work. Can you please help me out.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"> <Style x:Key="PhoenixWindowStyle" TargetType="{x:Type Window}"> <Setter Property="shell:WindowChrome.WindowChrome"> <Setter.Value> <shell:WindowChrome GlassFrameThickness="0" ResizeBorderThickness="1" CaptionHeight="32" CornerRadius="0"/> </Setter.Value> </Setter> <Setter Property="Background" Value="{DynamicResource DefaultBackgroundBrush}"/> <Setter Property="MinWidth" Value="100"/> <Setter Property="MinHeight" Value="100"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Window}"> <Grid Background="{DynamicResource BorderBrush}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="1"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="32"/> <RowDefinition Height="*"/> <RowDefinition Height="1"/> </Grid.RowDefinitions> <DockPanel Grid.Column="1" Grid.Row="0"> <TextBlock DockPanel.Dock="Left" Margin="0, 2, 0, 2" Padding="0"> <Image Width="24" Height="24" Margin="2" Source="{TemplateBinding Icon}" SnapsToDevicePixels="True" RenderOptions.EdgeMode="Aliased" /> <Run BaselineAlignment="Center" Text="{TemplateBinding Title}" Foreground="{DynamicResource DefaultBackgroundBrush}"/> </TextBlock> <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Right"> <!--This it the part I showed before --> <StackPanel Width="38" Height="32"> <StackPanel.Style> <Style TargetType="StackPanel"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Green"/> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="Background" Value="Red"/> </Trigger> </Style.Triggers> </Style> </StackPanel.Style> <Image Width="38" Height="32" Margin="0" Source="../Images/FrameControlIcons/38x32/close.png"/> </StackPanel> <!--/////////////////////--> </TextBlock> </DockPanel> <DockPanel Grid.Column="1" Grid.Row="1" > <ContentPresenter /> </DockPanel> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> 
4
  • Your code works as expected for me. It just turns the Background to Green when IsMouseOver is true and red when false Commented May 21, 2015 at 11:16
  • @SriramSakthivel Thanks for trying my code. I just tested it myselft in another place. It also worked for me. But this part ist acutaly in the header of a WindowChrome. I have no idea shy it doesnt work there. Any ideas? Now i added the complete source code of the custom window Commented May 21, 2015 at 11:37
  • Yes, I can reproduce the problem. Unfortunately I don't know the reason. Commented May 21, 2015 at 11:52
  • @SriramSakthivel Okay. But thanks anyway. Commented May 21, 2015 at 11:54

1 Answer 1

1

My co-worker recognized the problem. The Problem was, that my Image was covered by the CaptionHeight of the WindowChrome. When i set the CaptionHeigt to zero it works.

So i found a solution to make both work. The CaptionHeight (To drag the window around) and the mouse event on Element that are coverd by the CaptionHeight.

I had to set this property on the affected element:

shell:WindowChrome.IsHitTestVisibleInChrome="True" 

I found this Solution here:

How can I add a button to the WPF caption bar while using custom window chrome?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.