2009-06-18 6 views
0

J'utilise le contrôle multicolumn treeview que je trouve ici http://www.codeproject.com/KB/WPF/wpf_treelistview_control.aspxDimensionnement automatique colonne basé sur un modèle dans un ListView basé Multicolumn TreeView

La première colonne de ce contrôle qui consiste en un contrôle simulé de l'arborescence doit être autosized lorsqu'un noeud est développé/réduit.

Une aide?

Exemple 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> 

Merci, Jithu

Répondre

0

Essayez de définir une grille de données séparée et remplir et avec un élément qui contient les plus longues valeurs de la colonne. Puis DataBind la largeur de la colonne Aga.Controls Treeview à la largeur de colonne correspondante de votre DataGrid. De cette façon, la largeur des colonnes du contrôle TreeView est définie sur l'élément de colonne le plus long. Vous pouvez toujours masquer le DataGrid en définissant l'opacité sur zéro.

par exemple: Supposons que le nom DataGrid est "TestDataGrid" et il a une colonne appelée "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> 

Hope this helps.

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

http://www.go-mono.com/mono-downloads/download.html .. Télécharger Gtksharp ur système d'exploitation et d'ajouter refrence de ces dll en studio visuel ATK-sharp.dll, gdk-sharp.dll, glib-sharp.dll, gtk-sharp.dll et de l'utilisation utiliser Gtk; ... U obtiendra le 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(); 
} 
} 
Questions connexes