A read-only CheckBox in C# WPF

后端 未结 11 2076
南方客
南方客 2020-12-06 04:37

I am having a tricky problem, I want some slightly unusual behaviour from a checkbox and can\'t seem to figure it out. Any suggestions would be most welcome. The behaviour I

11条回答
  •  情话喂你
    2020-12-06 05:30

    What about data binding to the IsHitTestVisible property?

    For example, assuming an MVVM approach:

    1. Add a IsReadOnly property to your view model, initially set as true to allow click.
    2. Binding this property to CheckBox.IsHitTestVisible.
    3. After the first click, update your view model to set this value to false, preventing any further clicks.

    I don't have this exact requirement, I just needed an always read only checkbox, and it seems to solve the problem nicely. Also note Goran's comment below about the Focusable property.

提交回复
热议问题