Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
705
Background click sets ActiveItem
posted

Hello,

to reproduce this behavior, you have to, for example, open the sample xamGrid/Editing & Selection/Selection from the samples browser (I use v16.1) and click inside the white empty area at the bottom. This will activate the first cell / row and set the ActiveItem property. Even, if you set everything to "select rows only".

Can I disable this "feature"? So, that a click inside the background doesn't have any effect.

Regards

Stefan

Parents
  • 34810
    Verified Answer
    Offline posted

    Hello Stefan,

    I have been looking through the source code of the XamGrid and this behavior appears to be expected. In the XamGrid's internal handler for "GotFocus," if the currently editing cell and the current active cell is null, the first cell of the first row of the first visible column gets activated. I am unsure why exactly this is, but it is very explicitly created in the GotFocus handler. It is worth noting though, that if you set everything to select rows only, that cells can still be activated. Activated in this case essentially just means focused, whereas when something is selected, it goes into a different state. For example, if you had multiple row selection available, only the most recently selected row would be the "active" one.

    To disable this, I would recommend handling the PreviewMouseDown event on the XamGrid. Inside the handler for this event, you can place the following code:

    var x = e.OriginalSource;
    CellsPanel cp = Utilities.GetAncestorFromType(x as DependencyObject, typeof(CellsPanel), false) as CellsPanel;

    if (cp == null)
    {
      e.Handled = true;
    }

    Essentially, what this will do is it will check the visual tree of the "actual-clicked" element (e.OriginalSource) for a CellsPanel, which is the element that makes up the presenter for a row in the grid, whether this be a data row, header row, filter row, etc. Needless to say, this will be null when you click on the blank area of the grid, and by handling this event, you can prevent the grid from activating that first cell as the internal handler for MouseDown will not fire.

    I hope this helps. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

Reply Children