13

I have a StackPanel (1), with another StackPanel (2) inside.

SP 2 should be hidden (Opacity:0) until SP 1 is hovered. The mouse-over should change the style of SP2 to Opacity:100.

enter image description here

I've tried defining styles in the StackPanel resources, and using triggers there to then target the inside panel, but I'm not sure how I should be targeting the children from inside the trigger.

What would be a simple style structure to do this?

Yisela
  • 6,909
  • 5
  • 28
  • 51

1 Answers1

29

I do not fully understand what you need so i posted 2 samples.

Sample with colors for clarity :

1) when we have mouseover on sp1 sp2 getting green color

<Window x:Class="Prognoz.GP.DataCollection.TestMarkupProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Window.Resources>
    <Style x:Key="test" TargetType="StackPanel">
        <Setter Property="Background" Value="Red" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=StackPanel,AncestorLevel=1}, Path=IsMouseOver}" Value="True" >
                <Setter Property="Background" Value="Green" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<Grid>
    <StackPanel Width="400" Height="400" Background="Yellow">

        <StackPanel Width="350" Height="350" Style="{StaticResource test}"/>
    </StackPanel>
</Grid>
</Window>

2) when we have mouseover on sp2 sp2 getting green color

<Style x:Key="test" TargetType="StackPanel">
        <Setter Property="Background" Value="Red" />
        <Style.Triggers>
            <Trigger Property="StackPanel.IsMouseOver" Value="True" >
                <Setter Property="Background" Value="Green" />
            </Trigger>
        </Style.Triggers>
</Style>
Frank59
  • 3,141
  • 4
  • 31
  • 53
  • The first one is exactly what I needed. Thank you! – Yisela Apr 15 '13 at 21:11
  • funny thing: I've used the first sample with **Property="Visibility" Value="Collapsed"** as default. but then I can't see it on Designer :-). – itsho Jul 10 '13 at 15:18