我有一个绑定到 ObservableCollection 的 ListBox:
<ListBox ItemsSource="{Binding ObservableCollectionOfFoos}" />
ObservableCollection 包含 Foo 的实例,Foo 实现了 INotifyPropertyChanged。我正在尝试将 ListBoxItems 的属性绑定到 Foo 的属性。这是我尝试过的:
<DataTemplate DataType="{x:Type local:Foo}" >
<TextBlock Content="{Binding PropertyOfFoo}" Background="{Binding AnotherPropertyOfFoo}"/>
</DataTemplate>
这可行,但是,问题是我只能访问 TextBlock 的属性,而不是包含 ListBoxItem,因此,例如,Background 仅更改文本周围的颜色,而不是整个条目。我有一种感觉,我在这里使用了错误的工具来完成这项工作。
非常感谢正确方向的一点。