Home Forums WPF controls Xceed DataGrid for WPF ColumnManagerCell Control Template – Column Resizing

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • pcharbonneau
    Participant
    Post count: 3
    #44169 |

    Good morning,

    We have a Datagrid where we restyle the column headers to contain different search options using style triggers based on the parent column index (see code below). This is working well except for the fact that by restyling the control template we loose the ability to resize the columns.

     <Style TargetType="xcdg:ColumnManagerCell">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=ParentColumn.Index,RelativeSource={RelativeSource Self}}" Value="0">
                        <DataTrigger.Setters>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                       
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger.Setters>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=ParentColumn.Index,RelativeSource={RelativeSource Self}}" Value="1">
                        <DataTrigger.Setters>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger.Setters>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

    Changing the column order works fine and the search options follow but
    the control template seems to override the column thumb-gripper for resizing.

    Any suggestions on how to address this would be appreciated

    Tanks

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    If you want to modify the ColumnManagerCell’s template and keep its default functionalities, you would have to use the default template and modify it according to your needs. You may refer to the themes folder, which comes along with the Xceed package, and modify the template of the exact theme (used in your project) according to your requirements.

    You may find the Themes folder at the following path on your machine:

    C:\Program Files (x86)\Xceed\Xceed DataGrid for WPF v6.0\Themes

    pcharbonneau
    Participant
    Post count: 3

    Thank you for the quick response,

    After having fiddled with modifying the default template I arrived at a workable resizing and column reorder as suggested. The problem I am having though is that every time the DataGridCollectionView used as ItemSource for the DataGrid is refreshed the value of the textbox inside the control template for a column gets cleared. How would you suggest I bind these values to the datacontext of the view (in a MVVM scenario) ? Using an attached property maybe?

    Thanks in advance

    pcharbonneau
    Participant
    Post count: 3

    Just in case someone else stumble upon this, the solution I found was to create a proxy attached property for the datacontext. Bascally the issue with binding to the datagrid columns is that they are not part of the WPF elements tree and thus do not have access to the datacontext. The proxy property simply hold a ‘Data’ object referencing the DataContex (your viewmodel usually in a MVVM scenario).

    Using that attached property on the column then you can reference the datacontext and bind to it.

    See How to bind to data when the datacontext is not inherited.

    Hope this helps.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.