Selection not working for custom ListBoxItem due to internal SelectionHelper

4 posts, 1 answers
  1. Marc
    Marc avatar
    88 posts
    Member since:
    Jul 2011

    Posted 18 Dec 2012 Link to this post

    My special XListBox inherits from RadListBox. And since its item containers need special functionality too, I do the following:

    protected override DependencyObject GetContainerForItemOverride()
    {
        return new XListBoxItem(this);
    }

    However, this breaks the selection functionality of my XListBox - at least the part related to mouse clicks. Looking at the implementation of RadListBox I see the following:

    protected override DependencyObject GetContainerForItemOverride()
    {
      RadListBoxItem radListBoxItem = new RadListBoxItem();
      radListBoxItem.SelectionHelper = this.SelectionHelper;
      radListBoxItem.ParentSelector = (ListControl) this;
      return (DependencyObject) radListBoxItem;
    }

    Ok, I see! I need to set the SelectionHelper. BUT - AND THIS IS SOMETHING I DON'T UNDERSTAND - the "SelectionHelper"-property is an INTERNAL part of ListItem and cannot be set in my code. Why? This means that everybody with a special items container needs to implement selection functionality himself. In my opinion this doesn't make sense. Can you explain me the reasons behind this.

    For the moment I set the "SelectionHelper"-property via reflection. While this works, it doesn't seem like a perfect or durable solution.

    Any other ideas?

    Cheers,
    Stephan
  2. Marc
    Marc avatar
    88 posts
    Member since:
    Jul 2011

    Posted 18 Dec 2012 Link to this post

    What I forgot to mention before:

    My temporary reflection solution only works in trusted (in-/out-of browser) environments which makes it even more temporary than it was an hour ago.

    So, hopefully you can tell me a better/simpler solution.

    Regards,
    Stephan
  3. DevCraft banner
  4. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 21 Dec 2012 Link to this post

    Hello Stephan,

    Thank you for contacting us.

    This issue is already fixed. This properties are now set on the PrepareContainerForItemOverride of the ListControl. Please try with the latest available version of the controls and let us know if you still experience issues.

    Kind regards,
    Konstantina
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Marc
    Marc avatar
    88 posts
    Member since:
    Jul 2011

    Posted 30 Dec 2012 Link to this post

    Updated to Q3 1129. Problem solved! Thank you.
Back to Top