单击复选框隐藏多行
Hide multiple row on click of check box
我试图在选中复选框时隐藏两个列,我为此使用了 telerk radgrid 控件。网格包含五个列 ID、FName、LName、MobileNo、branch。选中复选框时想要隐藏 ID 和名称列请提示我的代码如下
C#代码:
class MainWindowViewModel
{
public MainWindowViewModel()
{
EmpList = ListOfEmpInfo();
}
private ObservableCollection<EmpInfo> ListOfEmpInfo()
{
return new ObservableCollection<EmpInfo>()
{
new EmpInfo(){ ID=1, City ="Pune" , FirstName ="Rahul" , LasttName ="Rathod", MobileNumber =123},
new EmpInfo(){ ID=2, City ="Mumbai" , FirstName ="Mahesh" , LasttName ="Yogaa", MobileNumber =456},
new EmpInfo(){ID=3, City ="Jalna" , FirstName ="Ganesh" , LasttName ="Kapadia", MobileNumber =178923}
};
}
public ObservableCollection<EmpInfo> EmpList
{
get;
set;
}
}
<Grid Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<CheckBox Content="Hide Show" IsChecked="{Binding IsVisible}" Height="40" Grid.Column="2"></CheckBox>
<telerik:RadGridView x:Name="radGridView" ItemsSource="{Binding EmpList}"
Grid.Column="1"
Margin="10,0,0,0" />
</Grid>
您可以在此处查看可行的解决方案:WPF Control TabItem visibility from a checkbox
当然,在你的情况下,你需要用 x:Name 命名你的复选框并像这样使用它:
<ColumnDefinition Width="150" Visibility="{Binding IsChecked,ElementName=chk,Converter={StaticResource b2v}}"/>
以防万一另一个 link 不可用,这里是 StaticResource:
<Window.Resources>
<BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>
我试图在选中复选框时隐藏两个列,我为此使用了 telerk radgrid 控件。网格包含五个列 ID、FName、LName、MobileNo、branch。选中复选框时想要隐藏 ID 和名称列请提示我的代码如下
C#代码: class MainWindowViewModel {
public MainWindowViewModel()
{
EmpList = ListOfEmpInfo();
}
private ObservableCollection<EmpInfo> ListOfEmpInfo()
{
return new ObservableCollection<EmpInfo>()
{
new EmpInfo(){ ID=1, City ="Pune" , FirstName ="Rahul" , LasttName ="Rathod", MobileNumber =123},
new EmpInfo(){ ID=2, City ="Mumbai" , FirstName ="Mahesh" , LasttName ="Yogaa", MobileNumber =456},
new EmpInfo(){ID=3, City ="Jalna" , FirstName ="Ganesh" , LasttName ="Kapadia", MobileNumber =178923}
};
}
public ObservableCollection<EmpInfo> EmpList
{
get;
set;
}
}
<Grid Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<CheckBox Content="Hide Show" IsChecked="{Binding IsVisible}" Height="40" Grid.Column="2"></CheckBox>
<telerik:RadGridView x:Name="radGridView" ItemsSource="{Binding EmpList}"
Grid.Column="1"
Margin="10,0,0,0" />
</Grid>
您可以在此处查看可行的解决方案:WPF Control TabItem visibility from a checkbox
当然,在你的情况下,你需要用 x:Name 命名你的复选框并像这样使用它:
<ColumnDefinition Width="150" Visibility="{Binding IsChecked,ElementName=chk,Converter={StaticResource b2v}}"/>
以防万一另一个 link 不可用,这里是 StaticResource:
<Window.Resources>
<BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>