2

我正在尝试实现一个包含图形组件集合的 ItemsControl。该组件应该能够使用 MouseWheel 事件进行缩放,但似乎 Scrollbar 正在捕获并首先处理该事件。我在这里这里找到的大多数文章都谈到让父母处理轮子,但我需要孩子处理轮子,我无法弄清楚正确的钩子。这是我的 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 事件?

提前致谢!

麦克风。

4

0 回答 0