0

我正在使用我在这里找到的多列树视图控件http://www.codeproject.com/KB/WPF/wpf_treelistview_control.aspx

此控件中包含模拟树视图控件的第一列需要在展开/折叠节点时自动调整大小。

有什么帮助吗?

示例 XAML

<UserControl x:Class="ListViewAsTreeView.XmlTree"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ListViewAsTreeView"    
xmlns:tree="clr-namespace:Aga.Controls.Tree;assembly=Aga.Controls">

<UserControl.Resources>        
    <local:RegImageConverter x:Key="RegImageConverter"/>
    <local:ComboList x:Key="MyComboSource"/>        
</UserControl.Resources>

<StackPanel>
    <tree:TreeList Name="_tree" local:DragAndDrop.DropEnabled="true"
                   MinHeight="40"
                   IsSynchronizedWithCurrentItem="True">
        <tree:TreeList.View>
            <GridView>
                <GridView.Columns>
                    <GridViewColumn Header="Name">                     
                        <GridViewColumn.CellTemplate>                  
                            <DataTemplate>
                                <StackPanel 
                                    Orientation="Horizontal">
                                    <tree:RowExpander/>
                                    <Image
                                        Source="{Binding 
                                        Converter={StaticResource RegImageConverter}}"  Margin="0, 0, 5, 0"/>
                                    <TextBlock
                                        Text="{Binding Name}">                                    
                                    </TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="Type" Width="Auto" 
                                    DisplayMemberBinding="{Binding Kind, UpdateSourceTrigger=PropertyChanged}"/>
                    <GridViewColumn Header="Data" Width="Auto" 
                                    DisplayMemberBinding="{Binding Data, UpdateSourceTrigger=PropertyChanged}"/>
                    <GridViewColumn Header="ComboSample" Width="Auto">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox Name="MyComboBox" ItemsSource="{StaticResource MyComboSource}" 
                                          IsEditable="True" IsEnabled="True" 
                                          Text="{Binding Name}">
                                </ComboBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView.Columns>
            </GridView>
        </tree:TreeList.View>
    </tree:TreeList>

    <ListBox local:DragAndDrop.DragEnabled="true">
        <ListBoxItem>Item 1</ListBoxItem>
        <ListBoxItem>Item 2</ListBoxItem>
        <ListBoxItem>Item 3</ListBoxItem>
    </ListBox>
</StackPanel>

谢谢, 吉图

4

2 回答 2

1
     Output : 
       Parent         Col1    Col2    Col3  
       |
       |____ Child    Data1   Data2  Data3
       |
       |____ Child2   Data1    Data2  Data3

http://www.go-mono.com/mono-downloads/download.html .. 为您的操作系统下载 Gtksharp 并在 Visual Studio atk-sharp.dll 、 gdk-sharp.dll 、 glib- 中添加这些 dll 的引用sharp.dll , gtk-sharp.dll 并使用 Gtk;...你将获得 TreeView

public class TreeViewExample
      {
public static void Main()
{
    Gtk.Application.Init();
    new TreeViewExample();
    Gtk.Application.Run();
}

public TreeViewExample()
{
    Gtk.Window window = new Gtk.Window("TreeView Example");
    window.SetSizeRequest(500, 200);

    Gtk.TreeView tree = new Gtk.TreeView();
    window.Add(tree);

    Gtk.TreeViewColumn Parent = new Gtk.TreeViewColumn();
    Parent.Title = "Parent";
    Gtk.CellRendererText Parent1 = new Gtk.CellRendererText();
    Parent.PackStart(Parent1, true);

    Gtk.TreeViewColumn ChildColoumn1 = new Gtk.TreeViewColumn();
    ChildColoumn1.Title = "Column 1";           
    Gtk.CellRendererText Child1 = new Gtk.CellRendererText();
    ChildColoumn1.PackStart(Child1, true);

    Gtk.TreeViewColumn ChildColumn2 = new Gtk.TreeViewColumn();
     ChildColumn2.Title = "Column 2";
    Gtk.CellRendererText Child2 = new Gtk.CellRendererText();
    ChildColumn2.PackStart(Child2, true);

    tree.AppendColumn(Parent);
    tree.AppendColumn(ChildColoumn1);
    tree.AppendColumn(ChildColumn2);

    Parent.AddAttribute(Parent1, "text", 0);
    ChildColoumn1.AddAttribute(Child1, "text", 1);
    ChildColumn2.AddAttribute(Child2, "text", 2);

    Gtk.TreeStore Tree = new Gtk.TreeStore(typeof(string), typeof(string), typeof(string));
    Gtk.TreeIter iter = Tree.AppendValues("Parent1");
    Tree.AppendValues(iter, "Child1", "Node 1");

    iter = Tree.AppendValues("Parent2");
    Tree.AppendValues(iter, "Child1", "Node 1","Node 2");          

    tree.Model = Tree;
    window.ShowAll();
}
}
于 2012-03-28T08:38:35.300 回答
0

尝试定义一个单独的 DataGrid 并使用包含最长列值的项目进行填充。然后将Aga.Controls Treeview 的列宽DataBind 到DataGrid 的相应列宽。这样,TreeView 控件的列宽设置为最长的列项。您始终可以通过将不透明度设置为零来隐藏 DataGrid。

例如:假设 DataGrid 名称是“TestDataGrid”并且它有一个名为“dgNameColumn”的列

<GridViewColumn Header="Name" **Width="{Binding ElementName=dgNameColumn, Path=ActualWidth}"**>                     
                    <GridViewColumn.CellTemplate>                  
                        <DataTemplate>
                            <StackPanel 
                                Orientation="Horizontal">
                                <tree:RowExpander/>
                                <Image
                                    Source="{Binding 
                                    Converter={StaticResource RegImageConverter}}"  Margin="0, 0, 5, 0"/>
                                <TextBlock
                                    Text="{Binding Name}">                                    
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

希望这可以帮助。

于 2009-08-28T00:49:51.767 回答