2009-07-09 3 views
2

Mon GroupStyle tête apparaît jamais dans le combobox ....Style Group en-tête apparaît

Le groupement fonctionne très bien .... Il est seul un problème de liaison, mais ne suis pas en mesure de comprendre.

<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> 

et le code derrière

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; 
    } 
} 

Répondre

9
Try changing the Binding Path from "Location" to "Name" 

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

... comme ça ...

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

semble fonctionner pour moi - réponse pourrait être acceptée si ... – santa