单击复选框隐藏多行

时间:2015-10-08 13:06:42

标签: wpf xaml mvvm telerik-grid

我试图隐藏两个colomn检查复选框我使用了telerk radgrid控件。网格包含五个colomn ID,FName,LName,MobileNo,branch。当选中复选框时要隐藏ID和名称colomn请提示我的代码如下

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>

1 个答案:

答案 0 :(得分:1)

您可以在此处查看有效的解决方案:WPF Control TabItem visibility from a checkbox

当然,在您的情况下,您需要使用x:Name命名您的复选框,并按如下方式使用它:

<ColumnDefinition Width="150" Visibility="{Binding IsChecked,ElementName=chk,Converter={StaticResource b2v}}"/>

以防其他链接不可用,这里是StaticResource:

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>