在我的WPF应用程序中,我想通过将[Browsable(false)]添加到某些属性来隐藏DataGrid中绑定的ItemsSource列。但是,无论是否有Browsable(false),所有列都可见。
我的模型:
如何使用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)来隐藏列?