tags:

views:

109

answers:

2

Hi, I have a control that inherits from TreeView (System.Windows.Controls.TreeView from WPF Framework) and it implements a GridViewColumnCollection to show columns next to the tree. However now I need to implement AllowColumnReorder in case we don't want users to reorder the columns, how can I achieve this? Here's the code for the TreeView:

    public class TreeListView : TreeView
    {
     protected override DependencyObject GetContainerForItemOverride()
     {
      return new TreeListViewItem();
     }

     protected override bool IsItemItsOwnContainerOverride(object item)
     {
      return item is TreeListViewItem;
     }

     #region Public Properties

     private GridViewColumnCollection _columns;

     public GridViewColumnCollection Columns
     {
      get
      {
       if (_columns == null)
       {
        _columns = new GridViewColumnCollection();
       }

       return _columns;
      }
     }

     public bool AllowColumnReorder { get; set; }

     #endregion
    }

Thank you!

A: 

Found the solution. It's not exactly in the class implementation but in the way is presented in the XAML with the GridViewHeaderRowPresenter.AllowsColumnReorder:

<Style TargetType="{x:Type controls:TreeListView}">
      <Setter Property="Template">
       <Setter.Value>
        <ControlTemplate TargetType="{x:Type controls:TreeListView}">
         <Border BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
          <DockPanel>
           <GridViewHeaderRowPresenter AllowsColumnReorder="False" Columns="{Binding Path=Columns,RelativeSource={RelativeSource TemplatedParent}}"
                                            DockPanel.Dock="Top"/>
           <ItemsPresenter/>
          </DockPanel>
         </Border>
        </ControlTemplate>
       </Setter.Value>
      </Setter>
     </Style>
Carlo
A: 

The determination of whether or not the columns should allow for sorting should be made by the control that is actually displaying the column data. For instance, if you are using a GridView to display the data found in the GridViewColumnCollection then you would want to set the AllowSorting property of the GridView to the value found in your AllowColumnReorder property.

Zensar
Yeah, the thing is right now I don't have time to put the property in the actual control, I plan to do it later though, for now the solution worked. Thanks.
Carlo