Make one tile Fixed in place / not moveable

2 posts, 0 answers
  1. jen
    jen avatar
    77 posts
    Member since:
    Jun 2009

    Posted 11 May Link to this post

    In my tileview I want the user to be able to rearrange any of the tiles except for the very first tile. How can I achieve this?

    Is there any sort of property on the tile that can prevent the tile from moving?

     

    My tiles Position property is bound to a property in the entity the tile represents. I have tried putting logic in the property set to prevent changes if the position is 0, but that is preventing ANY of the tiles from changing position

     

        <Style TargetType="{x:Type telerik:RadTileViewItem}">
            <Setter Property="Position" Value="{Binding Path=DisplayIndex, Mode=TwoWay}" />
        </Style>

        public int DisplayIndex
        {
            get { return DisplayIndex; }
            set
            {
                if (m_DisplayIndex !=0 && value != DisplayIndex && value > 0)
                {
                    m_DisplayIndex = value;
                }
                NotifyPropertyChanged("DisplayIndex");
            }
        }

     

    Any ideas or insight? thanks!

  2. Dinko
    Admin
    Dinko avatar
    415 posts

    Posted 16 May Link to this post

    Hello,

    If you want to prevent the first tile view item from moving you can subscribe to the PreviewTileDragStarted and PreviewTilePositionChanged events of the RadTileView control. In the events handlers, you can check if the current item has Position 0 (for example) and handle the events.
    <telerik:RadTileView PreviewTileDragStarted="tileView_PreviewTileDragStarted"
                         PreviewTilePositionChanged="tileView_TilePositionChanged"/>
    private void tileView_PreviewTileDragStarted(object sender, TileViewDragEventArgs e)
    {
        var item = e.DraggedItem as RadTileViewItem;
        if (item.Position == 0)
        {
            e.Handled = true;
        }
    }
     
    private void tileView_TilePositionChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        var item = e.OriginalSource as RadTileViewItem;
        if (item.Position == 0)
        {
            e.Handled = true;
        }
    }

    For your convenience, we have created sample project demonstrating this approach. Give it a try and let us know if it works for you. 

    Regards,
    Dinko
    Telerik by Progress
    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