拖放不能在GridView上运行

时间:2013-03-04 16:15:52

标签: c# windows-runtime windows-store-apps

我正在尝试在我的代码中实现类似的功能: 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%的时间内放下功能。 有什么建议吗?

1 个答案:

答案 0 :(得分: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后,它按预期工作。希望这会有所帮助。