Removing a tile from code behind

2 posts, 0 answers
  1. Conrad
    Conrad avatar
    1 posts
    Member since:
    Aug 2018

    Posted 23 Aug 2018 Link to this post

    Hi,

    Is it possible to remove a tile from a TileList dynamically? I have tried the code below to remove all delected tiles when the del key is pressed but I get an exception calling Items.Remove()

            private void OnKeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Delete)
                {
                    foreach (var item in tiledDashboardTileList.SelectedItems)
                    {
                        tiledDashboardTileList.Items.Remove(item);
                    }
                    tiledDashboardTileList.SelectedItems.Clear();
                    e.Handled = true;
                }
            }

  2. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 28 Aug 2018 Link to this post

    Hello Conrad,

    This would be expected when manipulating the Items collection of the control in such manner. Instead, you can access its bound source collection and remove the given item from it. This can be achieved through various approaches. For example, you can use the DataContext of the control as follows.
    private void tileList_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Delete)
                {
                    foreach (Club item in tileList.SelectedItems)
                    {
                        (tileList.DataContext as MyViewModel).Clubs.Remove(item);
                    }
                    tileList.SelectedItems.Clear();
                    e.Handled = true;
                }
            }

    Can you please give the approach a try?

    I hope it helps.

    Regards,
    Stefan
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top