VM.IsSelected set to false

5 posts, 2 answers
  1. Chad
    Chad avatar
    23 posts
    Member since:
    Aug 2013

    Posted 03 Feb 2015 Link to this post

    We're binding the IsSelected from our VM to the IsSelected of the grid row.

    When we reload and restore the IsSelected on the VM the IsSelected get set from true to false. (stack trace below)

    We have multiselect set to true on the grid. Can anyone demystify the stack below as to why this is happening?

    Thanks

    <Style TargetType="telerik:GridViewRow">
        <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>


    this.UseCase.Items.Clear();
    this.UseCase.AddItems(this._products);
     this.UseCase.FrameViewModel.ProductGridVM.Products = this.UseCase.Items;

    We're restoring IsSelected after this.


    >   Union.Catalog.Client.Product.ProductVMBaseBase.IsSelected.set   C#
        [Native to Managed Transition] 
        MS.Internal.Data.PropertyPathWorker.SetValue   
        MS.Internal.Data.ClrBindingWorker.UpdateValue  
        System.Windows.Data.BindingExpression.UpdateSource 
        System.Windows.Data.BindingExpressionBase.UpdateValue  
        System.Windows.Data.BindingExpression.UpdateOverride   
        System.Windows.Data.BindingExpressionBase.Update   
        System.Windows.Data.BindingExpressionBase.ProcessDirty 
        System.Windows.Data.BindingExpressionBase.Dirty
        System.Windows.Data.BindingExpressionBase.SetValue 
        System.Windows.DependencyObject.SetValueCommon 
        System.Windows.DependencyObject.SetValue   
        Telerik.Windows.Controls.DataControl.PersistIsSelectedProperty 
        Telerik.Windows.Controls.GridView.GridViewDataControl.PrepareContainerForItemOverride  
        Telerik.Windows.Controls.GridView.BaseItemsControl.Telerik.Windows.Controls.GridView.IGeneratorHost.PrepareItemContainer   
        Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer   
        Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.InsertContainer   
        Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.InsertNewContainer
        Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.AddContainerFromGenerator 
        Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.GenerateNextChild 
        Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.MeasureOverride   
        Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride
        System.Windows.FrameworkElement.MeasureCore
        System.Windows.UIElement.Measure   
        System.Windows.ContextLayoutManager.UpdateLayout   
        System.Windows.ContextLayoutManager.UpdateLayoutCallback   
        System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork
        System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks  
        System.Windows.Media.MediaContext.RenderMessageHandlerCore 
        System.Windows.Media.MediaContext.RenderMessageHandler 
        System.Windows.Threading.ExceptionWrapper.InternalRealCall 
        MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen   
        System.Windows.Threading.DispatcherOperation.InvokeImpl
        System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext   
        System.Threading.ExecutionContext.RunInternal  
        System.Threading.ExecutionContext.Run  
        System.Threading.ExecutionContext.Run  
        System.Windows.Threading.DispatcherOperation.Invoke
        System.Windows.Threading.Dispatcher.ProcessQueue   
        System.Windows.Threading.Dispatcher.WndProcHook
        MS.Win32.HwndWrapper.WndProc   
        MS.Win32.HwndSubclass.DispatcherCallbackOperation  
        System.Windows.Threading.ExceptionWrapper.InternalRealCall 
        MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen   
        System.Windows.Threading.Dispatcher.LegacyInvokeImpl   
        MS.Win32.HwndSubclass.SubclassWndProc  
        [Native to Managed Transition] 
        [Managed to Native Transition] 
        System.Windows.Threading.Dispatcher.PushFrameImpl  
        System.Windows.Threading.Dispatcher.PushFrame  
        System.Windows.Threading.Dispatcher.Run
        System.Windows.Application.RunDispatcher   
        System.Windows.Application.RunInternal 
        System.Windows.Application.Run 
        System.Windows.Application.Run 
        UnionShell.App.Main C#
  2. Answer
    Nick
    Admin
    Nick avatar
    593 posts

    Posted 03 Feb 2015 Link to this post

    Hi Tjaart,

    The problem is that the IsSelected property of the GridView row is a visual property that is used to identify if a Row is selected and thus put it in the correct visual state. Due the the UI Virtualization however, this porperty is unreliable on data level as the same row object is reused for multiple items. 

    You can use the SelectedItems property of RadGridView to keep synchronization between the data and the actual selected items.

    Hope this makes sense. 

    Regards,
    Nick
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Chad
    Chad avatar
    23 posts
    Member since:
    Aug 2013

    Posted 03 Feb 2015 in reply to Nick Link to this post

    Thanks for the info Nick.

    We're using the same pattern for the TreeView without a glitch... so far.

    Does it mean we're running the risk of the TreeView failing at some point?

    <Style x:Key="TreeViewItemStyle" TargetType="{x:Type t:RadTreeViewItem}" mc:Ignorable="d"
           d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=unionCategoryTree:CategoryVM}">
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />


  4. Answer
    Nick
    Admin
    Nick avatar
    593 posts

    Posted 03 Feb 2015 Link to this post

    Hi Tjaart,

    Basically the RadTreeView and RadGridVew(RadTreeListView shares same code base) have different layout and rendering strategies so the approach will probably work with RadTreeView. Nevertheless, using it with RadGridView or RadTreeListView is not recommended. 

    Regards,
    Nick
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Chad
    Chad avatar
    23 posts
    Member since:
    Aug 2013

    Posted 03 Feb 2015 in reply to Nick Link to this post

    Thanks Nick
Back to Top