我有以下xaml:
<Border x:Name="brdImg3" BorderThickness="2" BorderBrush="Black" Margin="10,5,5,5" Cursor="Hand">
<Image x:Name="image3" Stretch="Fill" Cursor="Hand"/>
</Border>
问题是,仅当图像源不为空时才显示手形光标。当Source为null时,仅当鼠标位于边框上时才会显示手形光标。我需要在鼠标位于边框时显示手形光标。我怎么能这样做?
答案 0 :(得分:0)
在Cursor中使用Converter,检查sources为null或为空。逻辑写得
Cursor={Binding Source,Converter={StaticResources CursorConverter}
public class CursorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!string.IsNullorEmpty(value.Tostring()))
{
return Cursor.Hand;
}
else
{
return Cursor.Arrow;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}