开发者

disabling a checkbox in a cell in datagrid based on some condition in wpf

开发者 https://www.devze.com 2023-03-18 03:26 出处:网络
I want to disable a cell containing a checkbox based on some condition. I have achieved this i.e. the checkbox does look blurred and disabled but when i click it the checkbox gets checked i.e. it is a

I want to disable a cell containing a checkbox based on some condition. I have achieved this i.e. the checkbox does look blurred and disabled but when i click it the checkbox gets checked i.e. it is actually not getting disabled. The following is the code i have tried out

In xaml

<toolkit:DataGridCheckBoxColumn Header="Del?" Binding="{Binding DeleteFlag, Mode=Default}" Width="45"  IsReadOnly="True" >
    <toolkit:DataGridCheckBoxColumn.ElementStyle>
        <Style TargetType="{x:Type CheckBox}">
            <Setter Property="IsEnabled" Value="{Binding Path=SortPos, 开发者_StackOverflowConverter={x:Static my:RowReadOnlyConverter.Instance}}" />
        </Style>
    </toolkit:DataGridCheckBoxColumn.ElementStyle>
</toolkit:DataGridCheckBoxColumn>

The "SortPos" highlighted above sends an integer value to "RowReadOnlyConverter" class which implements the IValueConverter interface which returns a bool value based on some condition. Although this works fine, the checkbox does not get disabled as mentioned above. I have also tried "IsHitTestVisible" instead of "IsEnabled". Does anyone know of any other property which might work or any other solution other than the above mentioned?

Please let me know if you need to have a look at "RowReadOnlyConverter" class or want a screenshot of the behavior.


just write like this in Xaml file ..here isstopprocess is the checkbox column ,is editable is another column based on this column isstopprocess column is disabiling..ok..

<my:DataGridTemplateColumn>
    <my:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox Name="chkIstopProcess" IsChecked="{Binding Path=IS_STOP_PROCESS}" IsEnabled="{Binding Path=IsEditable}" MinWidth="50"></CheckBox>
        </DataTemplate>
    </my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号