tags:

views:

717

answers:

2

My GroupStyle Header never appears in the combobox....

The Grouping is working fine....It's sole a binding issue but am not able to figure out.

            <DataTemplate>
                <Border Background="Red">
                    <TextBlock Text="{Binding Path=value}" />
                </Border>
            </DataTemplate>
        </ComboBox.ItemTemplate>
        <ComboBox.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel>
                        <TextBlock FontSize="12" FontWeight="Bold" Foreground="DarkGray">
                                <Button Content="{Binding Path=Location}"/>
                              <TextBlock  Text="{Binding Path=Location}" />
                            <Button>bbbb</Button>

                            </TextBlock>
                        <ItemsPresenter/>
                            </StackPanel>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ComboBox.GroupStyle>



    </ComboBox>

/// /// Interaction logic for Window1.xaml /// public class store { public string Location { get; set; } public string value { get; set; } }

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();

        ObservableCollection<store> myData = new ObservableCollection<store>();

        store a = new store();
        a.Location = "Group1";
        a.value = "Item 1 ";
        myData.Add(a);

        store ab = new store();
        ab.Location = "Bombay";
        ab.value = "Item 2";
        myData.Add(ab);

        store ac = new store();
        ac.Location = "Group2";
        ac.value = "Item 11 ";
        myData.Add(ac);

        ICollectionView view = CollectionViewSource.GetDefaultView(myData);
        view.GroupDescriptions.Add(new PropertyGroupDescription("Location"));

        DataContext = myData;
    }
}
+3  A: 
Try changing the Binding Path from "Location" to "Name"

<GroupStyle.HeaderTemplate>
   ...
    <Button Content="{Binding Path=Location}"/>
    <TextBlock  Text="{Binding Path=Location}" />
   ...
<GroupStyle.HeaderTemplate>

...like this...

<GroupStyle.HeaderTemplate>
   ...
    <Button Content="{Binding Path=Name}"/>
    <TextBlock  Text="{Binding Path=Name}" />
   ...
<GroupStyle.HeaderTemplate>
seems to work for me - answer could be accepted though...
santa
A: 

Hi,

Thanks for the answer......yes figured that out that WPF Header Group templates need "Name" to be harcoded as the Group Header....Because it internally fetches this from a property called "Name".

I have another question..... When we press any alphabet key and the group list is sorted one never reaches automatically the letter which we have pressed in the list. I mean for Keyboard navigation you would ideally want to reach the first item which matches the letter you have pressed...but this doesnt work in case I've added a CollectionView with PropertyGroupDescription??