我希望在光标位于WPF中的元素上时禁用滚动。
如果鼠标位于红色矩形上方,则应禁用滚动。 红色矩形位于滚动查看器上。
有什么想法吗?
答案 0 :(得分:0)
我让它使用这段代码:
<Window.Resources>
<converter:MouseOverToScrollBarVisibility x:Key="scrollVisibility" />
</Window.Resources>
<ScrollViewer VerticalScrollBarVisibility="{Binding IsMouseOver,
ElementName=rec,
Converter={StaticResource scrollVisibility}}">
<Rectangle Height="50" Width="50" Fill="Red" x:Name="rec"/>
</ScrollViewer>
然后定义这个转换器:
[ValueConversion(typeof(bool), typeof(ScrollBarVisibility))]
sealed class MouseOverToScrollBarVisibility : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((bool)value) ? ScrollBarVisibility.Hidden : ScrollBarVisibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}