Disable selecting in WPF DataGrid

后端 未结 12 846
天命终不由人
天命终不由人 2020-12-14 05:30

How can I disable selecting in a WPFTooklit\'s DataGrid? I tried modifying the solution that works for ListView (from WPF ListView turn off selecti

12条回答
  •  北海茫月
    2020-12-14 06:08

    All of the above are good ideas for easy hacks. However, they aren't doing exactly what is asked. The other answers are telling us how to unselect something selected by the user or hide the fact that something was selected by the user.

    However, I understand why these answers are given. It is not easy to provide the real solution.

    The real solution is to prevent selection in the first place, which it is not straightforward but it is doable with a few easy steps.

    Answer 1. You have to copy the style in Expression Blend (or find a copy of the style somewhere). 2. Change a single ItemPresenter setting. It was enough for me to set IsHitTestVisible="False" on the ItemPresenter.

    If you need more details, or an in-depth walk-thru for doing this, see my blog post:

    How to disable row selection in a WPF DataGrid?

提交回复
热议问题