Possible bug in DataBoundListBox causing Exception

Thread is closed for posting
2 posts, 0 answers
  1. Bernhard König
    Bernhard König avatar
    78 posts
    Member since:
    Nov 2009

    Posted 17 Apr 2011 Link to this post


    I found a possible bug. I reported a bug that was similar in an earlier support ticket but I think this is located somewhere else.

    What I'm doing is that I'd like to animate a Listbox-Item when it's first displayed on screen so that items doesn't just "pop in" when I use IsAsyncBalanceEnabled. The best way I found to do that was by handling it that way in the ItemStateChanged event handler:

    private void UnreadListBox_ItemStateChanged(object sender, ItemStateChangedEventArgs e)
        if (e.State == ItemState.Realized && UnreadListBox.IsItemInViewport(e.DataItem))
            var item = (this.UnreadListBox.GetContainerForItem(e.DataItem));
            RadAnimationManager.Play(item, tileAnimation);

    Most of the time this works fine althought I think IsItemInViewport does returns more items than needed (sometimes 25 if I don't start scrolling while about 5 are really on screen) but the animation framework is performant enough that animating more items than what are really on screen doesn't impact the app performance too much.

    Btw it would be great if the DataBoundListBox could support item animations (on insert, on remove, ...) out of the box in a future version.

    But now to the exception. Most of the time it works perfect, but sometimes i get a "Parameter is wrong" exception on IsItemInViewport call. The e.DataItem is correctly filled with an object at this time.

    Here's the stack trace:

    bei MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
    bei MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
    bei MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
    bei System.Windows.UIElement.TransformToVisual(UIElement visual)
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.IsItemInViewport(Object dataItem)
    bei bpk.feed7.View.FolderView.UnreadListBox_ItemStateChanged(Object sender, ItemStateChangedEventArgs e)
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.OnItemStateChanged(Object item, ItemState state)
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.OnContainerStateChanged(RadVirtualizingDataControlItem container, IDataSourceItem item, ItemState state)
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.GetContainerForItem(IDataSourceItem item, Int32 insertAt)
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.GetContainerForItem(IDataSourceItem item, Boolean insertLast)
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.ManageVisualSequenceFromViewportBottom()
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.BalanceVisualSpace()
    bei Telerik.Windows.Controls.RadVirtualizingDataControl.OnBalanceTimerTick(Object sender, EventArgs e)
    bei System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
    bei MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

    I can again send you my current source code if you need, but it's not 100 % reproducable, althought it happens on a pretty regular basis so after a while playing around in the app, it will appear.

  2. Deyan
    Deyan avatar
    2147 posts

    Posted 18 Apr 2011 Link to this post

    Hi Bernhard,

    Thanks for writing.

    I would like to note that in the upcoming Q1 2011 SP1 release of RadControls for Windows Phone 7 the behavior of the RadDataBoundListBox control  when the IsAsyncBalanceEnabled property is set to true will be slightly different. We have updated this logic for better user experience so that items will no longer appear one after another but all at once. In other words, the asynchronuous balance logic will be triggered until after the viewport is filled with visual containers. We are also eager to see why the IsItemInViewport method returns true more times than expected. For this we will need your demo app as well.

    As for the exception you are getting, it is related to the TransformToVisual method defined in the FrameworkElement. This method would throw an InvalidOperationException when the elements it is used on are not in the correct layout state. This seems to be issue in your case too. We will try to prevent this exception from happening though.

    Thanks for the time taken to send us a demo app and do not hesitate to get back to us anytime you need further assistance or have feedback to share.

    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top