【发布时间】:2015-10-04 12:12:49
【问题描述】:
在我的 WPF 应用程序中,我想通过将 [Browsable(false)] 添加到某些属性来隐藏具有绑定 ItemsSource 的 DataGrid 中的列 但是,无论有无 Browsable(false),所有列都是可见的。
我的模特:
public class Room : INotifyPropertyChanged
{
private int id;
...
[Browsable(false)]
public int Id
{
get
{
return this.id;
}
set
{
this.id = value;
this.OnPropertyChanged("Id");
}
}
...
public Room()
{
}
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler propertyChangedEventHandler = this.PropertyChanged;
if (propertyChangedEventHandler != null)
{
propertyChangedEventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
查看:
<DataGrid Grid.Row="1" ItemsSource="{Binding Rooms}" SelectedItem="{Binding SelectedRoom, Mode=TwoWay}" />
如何使用 Browsable(false) 隐藏列?
【问题讨论】:
标签: c# wpf visual-studio datagrid