2013-03-04 146 views
1

我想在我的代碼來實現類似的功能: http://www.codeproject.com/Articles/536519/Extending-GridView-with-Drag-and-Drop-for-Grouping拖放不工作的GridView

我繼續從該項目複製相關文件(Customized.xaml,Customized.xaml.cs,分組.xaml,Grouped.xaml.cs和GridViewEx.cs)到我的項目。 我已經改名爲必要的項目爲它來編譯,但是我現在面臨與GridView控件不滾動和項目的重新排序不工作在觸摸屏的一個問題。 (奇怪的是,我仍然可以用鼠標移動物品,但Drop沒有一致地註冊)。 好像有某種佈局問題或必須有滾動不是在所有工作中,將一個原因,只有放棄與鼠標的工作,和拖放功能工作的約50%的鼠標的時間。 有什麼建議嗎?

+1

請發表您的代碼更好的解決方案(想法)。 – linguini 2013-03-04 16:20:44

+0

在我的初始頁面上,我導航到使用Frame.Navigate(typeof(Customized))定製; 自定義和分組(.xaml和.cs)與上面的鏈接完全相同。 – 2013-03-04 16:22:50

+0

@YuriDoubov我和你有同樣的問題,你有解決這個問題嗎?我注意到,當我拖動一個項目時,它在我將項目釋放到提示項目的位置時起作用。但是稍高或過低會導致OnDrop功能無法激活。 – foboi1122 2013-03-30 01:23:55

回答

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後,它的工作如預期。希望這可以幫助。

+0

你是怎麼把2連在一起的? – 2013-04-08 17:41:47

+0

我通過將上面的代碼放在我的app.xaml下的中來鏈接它。請注意,在上面的代碼中,我的GridViewEx是在本地命名空間下聲明的。如果你已經在說... APP_NAME.Controls宣佈你GridViewEx,那麼你就必須通過添加行添加到您的App.xaml「的xmlns:控制=」使用:APP_NAME.Controls」那麼,你也需要。修改<樣式的TargetType =「本地:GridViewEx」>到<樣式的TargetType =「控制:GridViewEx」>。一旦你正確地做到這一點,GridViewEx應自動識別這種風格。 – foboi1122 2013-04-09 06:12:02