我正在学习 WPF,并且一直在使用数据绑定(bind)。我有一个 TreeView,它 ItemSource
设置为 ObserveableCollection<UIBrowserItem>
.
我的绑定(bind)看起来像:
<TreeView>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="Header" Value="{Binding Path=Title}"/>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
还有我的UIBrowserItem
非常基础:
public class UIBrowserItem
{
public string Title = "Test";
}
但是 TreeView 中的 Items 不会有标题集..
如果您需要更多信息,请告诉我
最佳答案
您只能绑定(bind)到公共(public)属性,您有一个公共(public)字段。您的代码应该是:
public class UIBrowserItem
{
private String title = "Test";
public string Title
{
get { return title; }
set { title = value; }
}
如果标题可以在运行时改变,你还需要实现INotifyPropertyChanged
。
关于c# - 简单的 WPF 绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23415076/