我的GroupStyle标头永远不会出现在组合框中。
分组工作正常。...这只是一个有约束力的问题,但无法弄清楚。
<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>
和后面的代码
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;
}
}
最佳答案
Try changing the Binding Path from "Location" to "Name"
<GroupStyle.HeaderTemplate>
...
<Button Content="{Binding Path=Location}"/>
<TextBlock Text="{Binding Path=Location}" />
...
<GroupStyle.HeaderTemplate>
...像这样...
<GroupStyle.HeaderTemplate>
...
<Button Content="{Binding Path=Name}"/>
<TextBlock Text="{Binding Path=Name}" />
...
<GroupStyle.HeaderTemplate>
关于wpf - 组样式标题永远不会出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1102584/