【发布时间】:2011-04-12 22:39:32
【问题描述】:
我很难用一个简单的文本框来显示我想要的内容。 基本上我有一个来自这个数据文件 xml 的分组列表框:
<Hosts>
<Host foo="aaa">
<usable>1</usable>
</Host>
<Host foo="bbb">
<usable>1</usable>
</Host>
</Hosts>
然后我有以下代码:
<CollectionViewSource x:Key="cvs"
Source="{Binding Source={StaticResource HostsData}}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="@foo" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<DataTemplate x:Key="categoryTemplate">
<TextBlock Text="test"
FontWeight="Bold"
Background="Gold"
Margin="0,5,0,0" />
</DataTemplate>
...
<ListBox Name="myList"
Grid.Row="0"
Grid.Column="1"
TextBlock.FontSize="9"
Margin="2"
ItemsSource="{Binding Source={StaticResource cvs}}"
ItemTemplate="{StaticResource MachinesTemplate}">
<ListBox.GroupStyle>
<GroupStyle HeaderTemplate="{StaticResource categoryTemplate}" />
</ListBox.GroupStyle>
</ListBox>
所以我有我的分组列表框,但测试框内容是空的。它是“gold”,如果我设置 Text="test",它会按照应有的方式加粗,但我无法让它显示“foo”内容(aaa,bbb)。
到目前为止,我已经尝试了各种绑定但没有成功..
【问题讨论】:
标签: c# wpf xaml listbox groupstyle