开发者

WPF Style Triggers from another control

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. 开发者_开发百科


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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜