这样怎么样:
<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}}" />
然后使用这个值转换器:
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();
}
}