RadTileList - Clicking contained button changes selection

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    42 posts
    Member since:
    Jun 2013

    Posted 27 Jun Link to this post

    I'm using a RadTileList to display a set of tiles from a collection stored in a viewmodel via the RadTileList's ItemSource and ItemTemplate properties. Additionally, I'm allowing multi-tile selection via SelectionMode="Extended".

    In my Tile's ItemTemplate, I've defined 3 buttons that access functionality specific to the containing tile. 

    I've noticed that clicking directly on any of the buttons contained in a tile toggles the selected state of the containing tile. I'd prefer for a click directly on a contained button to not change the Tile's selected state in any way. So far though, I haven't found any satisfactory way of accomplishing this.

    Thanks for you input.

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 29 Jun Link to this post

    Hello Jeff,

    Unfortunately, with the current implementation of the RadTileList control, the MouseLeftButtonUp event is bubbled up to the control in all cases which in turn triggers the selection logic. A good way to handle this would be to introduce a SelectionChanging event and cancel the process when certain conditions are met. I have thus logged a new feature request in our feedback portal regarding such functionality. You can subscribe to the item in order to get notified about any changes in its status.

    The only workaround I can offer for the moment is to set your custom flag in the MouseLeftButtonUp (and/or MouseRightButtonUp) event(s) and manually update the SelectedItems collection once the SelectionChanged event is triggered. Here's an example:

    private bool IsButtonClicked = false;
    private object ItemToRemove;
    private IList ItemsToAdd;
      
    private void RadTileList_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.OriginalSource is Button ||
            (e.OriginalSource as FrameworkElement).ParentOfType<Button>() != null)
        {
            IsButtonClicked = true;
        }
    }
      
    private void RadTileList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (IsButtonClicked && e.AddedItems.Count > 0)
        {
            ItemToRemove = e.AddedItems[0];
            ItemsToAdd = e.RemovedItems;
            IsButtonClicked = false;
      
            var tileList = sender as RadTileList;
            tileList.SelectedItems.Remove(ItemToRemove);
            foreach (var item in ItemsToAdd)
            {
                tileList.SelectedItems.Add(item);
      
            }
        }
    }

    I hope you find such an approach applicable.

    Regards,
    Dilyan Traykov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top