0

当光标位于 WPF 中的元素上时,我想禁用滚动。 在此处输入图像描述

如果鼠标位于红色矩形上,则应禁用滚动。红色矩形位于滚动查看器上。

任何想法?

4

1 回答 1

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();
    }
}
于 2013-02-15T13:53:56.133 回答