Dynamic assignment of LabelTemplate gives exception

Thread is closed for posting
2 posts, 0 answers
  1. Anthony
    Anthony avatar
    3 posts
    Member since:
    Jan 2013

    Posted 15 Feb 2014 Link to this post


    I'm trying to programmatically assign the Axis.LabelTemplate property during run time and receive the ArgumentOutOfRangeException.

    After decompiling Telerik.Windows.Controls.PresenterBase it appears that the exception is occurring when the ClearPresenters() method is called.

    The line containing "this.renderSurface.Children.Remove(elements[i] as UIElement);" is attempting to access an item that was removed in the line preceding it.

            internal void ClearPresenters(IList elements)
                if (this.renderSurface == null)
                    for (int i = elements.Count - 1; i >= 0; i--)
                       this.renderSurface.Children.Remove(elements[i] as UIElement);

    Is there another way to programmatically assign this value.  I tried using a DataTemplateSelector, however, received a similar error message as it too calls the ClearPresenters method.

  2. Rosy Topchiyska
    Rosy Topchiyska avatar
    586 posts

    Posted 19 Feb 2014 Link to this post

    Hello Anthony,

    Thank you for contacting us.

    From the provided information it is not completely clear how you assign the LabelTemplate property. I have attached a project that demonstrates how to set a LabelTemplate runtime. Could you please take a look and see if this works for you. If not, could you please modify it in order to reproduce the error.

    I look forward to your reply. 

    Rositsa Topchiyska
    If you want to get updates on new releases, tips and tricks and sneak peek previews directly from the developers working on the UI for Windows Phone, subscribe to the blog feed now.
Back to Top