views:

19

answers:

1

Hi, I have an image that i want to make it when the user hover with mouse over it, another image next to it will be displayed.

The code below, doesn't work:

            <Image Source="volumen.png">
                <Image.Style>
                    <Style>
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="bar_volume" Property="Visibility" Value="Visible" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Image.Style>
            </Image>
            <Image Source="volumen_bar.png" Name="bar_volume" Visibility="Hidden" />

Any ideas how can i set another control setter property from another control trigger?

10x.

A: 

How about like this:

 <UserControl.Resources>       
      <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
 </UserControl.Resources>       
 <Image Name="firstImage" Source="volumen.png"/>
 <Image Source="volumen_bar.png" Name="bar_volume" Visibility="{Binding IsMouseOver,ElementName=firstImage, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />

and then use this valueconverter for it:

public class BoolToVisibilityConverter:IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
         return (bool)value ? Visibility.Visible : Visibility.Hidden;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
         throw new NotSupportedException();
    }
}
Goblin
If i need to write code i can just use MouseOver and set the Visibility of the object ... I want it to be purely XAML. But thanks anyway.
aviv
The problem is that the two Images cannot 'see' each-other. So, if you want this behaviour, you need to put both images inside a container, and let the Containers style set the styling - problem again being that you can only 'see' the properties of the container in the container's style.
Goblin