4

我在 wpf 中有一个树视图,它是使用下面的 xaml 构建的。这是一个结构良好的数据源,我在拖放时遇到了很多麻烦。我尝试了几种方法,都无济于事。谁能告诉我做这种事情的标准程序是什么?

<TreeView x:Name="_treeView" ItemsSource="{Binding}"   Grid.Row="0" Grid.Column="0">
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type Logic:Statement}"
                              ItemsSource="{Binding Path=PagedChildren}">
                    <TextBlock Text="{Binding StatementName}"/>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type Logic:StatementPage}"
                              ItemsSource="{Binding Path=Children}">
                    <WrapPanel>
                        <TextBlock Text="Page: "/>
                        <TextBlock Text="{Binding PageIndex}"/>
                    </WrapPanel>
                </HierarchicalDataTemplate>

                <DataTemplate DataType="{x:Type Logic:StatementFund}">
                    <Border  HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="2" CornerRadius="25">
                        <WrapPanel Margin="30 0 30 0" Width="150" Height="150" >
                            <StackPanel>
                                <TextBlock Text="Fund"/>
                                <WrapPanel>
                                    <TextBlock Text="Fund: "/>
                                    <TextBlock Text="{Binding FundNumber}"/>
                                </WrapPanel>
                                <WrapPanel Margin="10 0 0 0">
                                    <TextBlock Text="{Binding ColumnIndex}"/>
                                </WrapPanel>
                            </StackPanel>
                        </WrapPanel>
                    </Border>
                </DataTemplate>
                <DataTemplate DataType="{x:Type Logic:StatementPreviousCycle}">
                    <Border  HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="2" CornerRadius="25">
                        <WrapPanel Margin="30 0 30 0" Width="150" Height="150" >
                            <StackPanel>
                                <TextBlock Text="Previous Cycle"/>
                                <WrapPanel>
                                    <TextBlock Text="Fund: "/>
                                    <TextBlock Text="{Binding FundNumber}"/>
                                </WrapPanel>
                                <WrapPanel Margin="10 0 0 0">
                                    <TextBlock Text="{Binding ColumnIndex}"/>
                                </WrapPanel>
                            </StackPanel>
                        </WrapPanel>
                    </Border>
                </DataTemplate>

            </TreeView.Resources>
        </TreeView>
4

1 回答 1

4

我使用本网站上的技术进行一般拖放。

tree view can get messy, if you want to know which node you are preivewMouseDown'ing on, to then use as your drag item you can end up walking the visual tree. there is some code to do that here. another way is to subclass treeview, and treeviewitem, then you can override the preview mouse down on each tree view item, and tell your derived parent treeview about it, which could set the tree view item to be the selected item.

于 2009-11-25T00:44:22.310 回答