views:

172

answers:

2

I am using a datagrid with a combox that should change the grouping field. I am using the following xaml to define the general grouping template :

<DataGrid.GroupStyle>
        <GroupStyle>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <Expander>
                                    <Expander.Header>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="NEEDS TO BE BINDED..."/>
                                        </StackPanel>
                                    </Expander.Header>
                                    <ItemsPresenter />
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </DataGrid.GroupStyle>

I only need to be able to 'reach' that TextBlock within the expander to be able to output the selected grouping applied.

Please help....

+1  A: 

If you want to display the common value of the property being grouped by, that will be available as CollectionViewGroup.Name, so you can just do:

<TextBlock Text="{Binding Name}"/>
Quartermeister
Thanks. I have finally used a different approach as i needed to have more info that i had to fetch manually. I have posted my solution.
OrPaz
A: 

I have solved my issue by adding a nested class that contains the currently selected grouping (which i manually set ofcourse) + more details i need. Then binding to the class property by using :

<TextBlock Text="{Binding Source={StaticResource GroupingSubject},Path=Name}"/>

Ofcourse that i had to declare the class within the xaml resources as follows :

<local:GroupingName x:Key="GroupingName"/>

My nested class looks as follows :

public class GroupingSubject 
{
    private static String name = null;
    private static Object groupType = null;

    public GroupingSubject() { }
    public static String Name
    {
        get { return name; }
        set { name = value; }
    }

    public static Object GroupType
    {
        get { return groupType; }
        set { groupType = value; }

    }

}

Now all is well...

OrPaz