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 をダウンロードし、これらの dll の参照を Visual Studio atk-sharp.dll 、 gdk-sharp.dll 、 glib- に追加します。 Sharp.dll 、 gtk-sharp.dll および Gtk を使用した使用。... U は 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 の列幅を DataGrid の対応する列幅に DataBind します。そうすれば、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 に答える