Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group Style Header never appears

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.

<ComboBox Height="23" Margin="33,45,125,0" Name="comboBox1" VerticalAlignment="Top"  ItemsSource="{Binding}" >
    <ComboBox.ItemTemplate>
        <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>

and code behind

public class Store
{
    public string Location { get; set; }
    public string value { get; set; }
}

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

        var myData = new ObservableCollection<Store>
        {
            new Store { Location = "Group1", value = "Item 1" },
            new Store { Location = "Bombay", value = "Item 2" },
            new Store { Location = "Group2", value = "Item 11" }
        }

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

        DataContext = myData;
    }
}

1 Answers

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>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!