none
gridview 拖拽问题 RRS feed

  • 问题

  • 我想实现从一个gridview 拖动 item 到另一个 gridview item

    //源gridview:

    <GridView Background="#FFE5E1F3"
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemsGridView"
                AutomationProperties.Name="minfo"
                SelectionMode="Single"
                ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
                ScrollViewer.VerticalScrollBarVisibility="Auto"
                ScrollViewer.VerticalScrollMode="Auto"
                AllowDrop="True" CanDragItems="True" CanReorderItems="True"
                IsSwipeEnabled="false" VerticalAlignment="Top" Height="700" SelectionChanged="OnChange_SelectedMail" DragItemsStarting="OnDragStarting_MailList">
                <GridView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="30" />
                                <RowDefinition Height="30"/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="{Binding Subject}" FontWeight="{Binding UnRead}"  Padding="5,7,0,0" Height="30" Width="498" FontSize="15" />
                            <TextBlock Text="{Binding Date}" FontWeight="{Binding UnRead}" Foreground="#FF698D85" Grid.Row="1" FontSize="12" Height="30" Width="100" HorizontalAlignment="Right" FontStyle="Normal"/>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>

    //拖拽去文件夹gridview:

              <GridView x:Name="mailaccout"
                        ItemsSource="{Binding Source={StaticResource FTree}}"
                        IsSwipeEnabled="false"
                        SelectionMode="Single"
                        Grid.ColumnSpan="1"
                        Grid.Row="1"
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ScrollViewer.VerticalScrollBarVisibility="Auto" TabIndex="1"
                        ScrollViewer.VerticalScrollMode="Auto" SelectionChanged="OnChange_MailFolder"
                        >
                   <GridView.ItemTemplate>
                        <DataTemplate>
                            <Grid AllowDrop="True" DragEnter="OnDragEnter_AccoutGridView" DragLeave="OnDragLeave_AccoutGridView" Drop="OnDrop_AccoutGridView">
                                <TextBlock Padding="50,10,0,0" Width="250" Height="40" >
                                <Run Text="{Binding Title}"/>
                            </TextBlock>
                            </Grid>
                        </DataTemplate>
                    </GridView.ItemTemplate>
            </GridView>

    //放下item的事件:

    void MainPage::OnDrop_AccoutGridView(Platform::Object^ sender, Windows::UI::Xaml::DragEventArgs^ e)
    {

    auto mitem = safe_cast<mInfo^>(e->Data->Properties->Lookup("Item"));

    这里我如何获得目标 gridview 的 item(另一个gridview的item)

    }

    这里我如何获得目标 gridview 的 item(另一个gridview的item)也就是sender元素的

    item类


    2014年6月8日 8:28

答案

  • 你好,graycat,

    如何获取GridView的Item,Sender元素的Item类?

    从你的代码上来看,源GridView的Item为一个Grid里面有两个TextBlock,那么你应该写成 e.OriginalSource as Grid (这是C#代码,C++代码我不是很熟悉,不过应该也是这么来用) 来获取这个Grid

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年6月9日 7:07
    版主