1

我正在尝试在我的代码中实现类似的功能:http: //www.codeproject.com/Articles/536519/Extending-GridView-with-Drag-and-Drop-for-Grouping

我继续将该项目中的相关文件(Customized.xaml、Customized.xaml.cs、Grouped.xaml、Grouped.xaml.cs 和 GridViewEx.cs)复制到我的项目中。我已经重命名了编译所需的项目,但是我遇到了 GridView 不滚动的问题,并且项目的重新排序在触摸屏上不起作用。(奇怪的是,我仍然可以用鼠标移动项目,但是 Drop 没有一致地注册)。似乎存在某种布局问题,或者必须有原因滚动根本不起作用,拖放只能使用鼠标,而拖放功能大约有 50% 的时间使用鼠标。有什么建议吗?

4

1 回答 1

1

我不知道您现在是否已经解决了您的问题,但我最终弄清楚了为什么我会遇到这个问题。事实证明,您不仅必须导入 GridViewEx.cs 和相关的 Grouped.xaml 和 Grouped.xaml.cs,还必须导入“generic.xaml”中的内容。

<Style TargetType="local:GridViewEx">
    <Setter Property="Padding" Value="0,0,0,10" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="TabNavigation" Value="Once" />
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
    <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled" />
    <Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False" />
    <Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
    <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False" />
    <Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
    <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
    <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True" />
    <Setter Property="IsSwipeEnabled" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:GridViewEx">
                <Border BorderBrush="{TemplateBinding BorderBrush}"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <ScrollViewer x:Name="ScrollViewer"
                                        TabNavigation="{TemplateBinding TabNavigation}"
                                        HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                        HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                        IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}"
                                        VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                        VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                        IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}"
                                        IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                        IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                        ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}"
                                        IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                        BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}">
                        <StackPanel Orientation="Horizontal">
                            <Border Width="60" x:Name="NewGroupPlaceHolderFirst" 
                                    Background="Transparent" Padding="{TemplateBinding Padding}" 
                                    Visibility="{Binding AllowNewGroup, Converter={StaticResource VisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}"/>
                            <ItemsPresenter 
                                Header="{TemplateBinding Header}" 
                                HeaderTemplate="{TemplateBinding HeaderTemplate}"
                                HeaderTransitions="{TemplateBinding HeaderTransitions}"
                                Padding="{TemplateBinding Padding}"/>
                            <Border Width="60" x:Name="NewGroupPlaceHolderLast" 
                                    Background="Transparent" Padding="{TemplateBinding Padding}" 
                                    Visibility="{Binding AllowNewGroup, Converter={StaticResource VisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}"/>
                        </StackPanel>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

在我将此样式链接到我的 Grouped.xaml 后,它按预期工作。希望这可以帮助。

于 2013-04-05T18:42:30.520 回答