This is a migrated thread and some comments may be shown as answers.

RadTileList - Clicking contained button changes selection

1 Answer 148 Views
TileList
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 27 Jun 2017, 04:07 PM

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.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 29 Jun 2017, 12:27 PM
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 you to write beautiful native mobile apps using a single shared C# codebase.
Tags
TileList
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or