WPF在ScrollViewer上禁用鼠标滚轮,让孩子们处理它

时间:2017-04-11 13:43:11

标签: wpf events scrollviewer mousewheel routed

我正在尝试实现一个包含图形组件集合的ItemsControl。该组件应该能够使用MouseWheel事件进行缩放,但看起来Scrollbar首先捕获并处理事件。我发现的大多数文章herehere都说让父母处理轮子,但是我需要孩子来处理轮子,我无法弄清楚正确的钩子。这是我的TiledGrid,它的核心是ItemsControl:

<ItemsControl x:Class="Grapes.Common.Controls.TiledGrid.TiledGrid"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:Grapes.Common.Controls.TiledGrid"
         xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="300" x:Name="itemsGrid" 
              ScrollViewer.CanContentScroll="True" >
        <!--ItemTemplate="{Binding ItemTemplate}"-->
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="Black" BorderThickness="1"
                        Padding="3" Margin="3" >
                    <HeaderedContentControl
                        HeaderTemplate="{Binding HeaderTemplate,ElementName=itemsGrid}" Header="{Binding}"
                        ContentTemplate="{Binding ItemTemplate,ElementName=itemsGrid}" Content="{Binding}"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                       >
                        <HeaderedContentControl.Template>
                            <ControlTemplate TargetType="HeaderedContentControl">
                                <DockPanel>
                                    <ContentPresenter DockPanel.Dock="Top" ContentSource="Header" />
                                    <ContentPresenter />
                                </DockPanel>
                            </ControlTemplate>
                        </HeaderedContentControl.Template>
                    </HeaderedContentControl>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
        <local:UniformGridPanel Rows="{Binding RowCount,ElementName=itemsGrid}" 
                                Columns="{Binding ColumnCount,ElementName=itemsGrid}" 
                              >

        </local:UniformGridPanel>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.Template>
            <ControlTemplate>
                <Border
        BorderThickness="{TemplateBinding Border.BorderThickness}"
        Padding="{TemplateBinding Control.Padding}"
        BorderBrush="{TemplateBinding Border.BorderBrush}"
        Background="{TemplateBinding Panel.Background}"
        SnapsToDevicePixels="True">
                    <ScrollViewer
                Padding="{TemplateBinding Control.Padding}"
                Focusable="False" FlowDirection="RightToLeft" CanContentScroll="True" SnapsToDevicePixels="True"
                        >

                <ItemsPresenter FlowDirection="LeftToRight">

                </ItemsPresenter>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </ItemsControl.Template>
    </ItemsControl>

如何阻止ItemsControl.Template中的ScrollViewer处理MouseWheel事件?

提前致谢!

麦克

0 个答案:

没有答案