Demo例子:
ViewModel 内容
public class MainWindowViewModel : BindableBase
{
private string _title = "Prism Application";
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
private string _name;
public string Name
{
get { return _name; }
set { SetProperty(ref _name, value); }
}
private Visibility _isEnable;
public Visibility IsEnable
{
get { return _isEnable; }
set { SetProperty(ref _isEnable, value); }
}
public MainWindowViewModel()
{
IsEnable = Visibility.Visible;
}
}
View内容:
<Grid>
<FrameworkElement x:Name="dummyElement" Visibility="Collapsed" />
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn
Header="Test"
Visibility="{Binding DataContext.IsEnable,
Source={x:Reference dummyElement}}" />
</DataGrid.Columns>
<DataGridTextColumn Header="123" />
<DataGridTextColumn Header="123" />
<DataGridTextColumn Header="123" />
<DataGridTextColumn Header="123" />
</DataGrid>
</Grid>
效果:
1、当Visibility 为Visible 时
2、1、当Visibility 为Collapsed
时
可看到列隐藏了
标签:set,string,XAML,private,Visibility,WPF,public,isEnable From: https://www.cnblogs.com/ganbei/p/16968989.html