This is a migrated thread and some comments may be shown as answers.

Selection not working for custom ListBoxItem due to internal SelectionHelper

3 Answers 95 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 18 Dec 2012, 12:38 PM
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

3 Answers, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 18 Dec 2012, 01:42 PM
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
0
Accepted
Konstantina
Telerik team
answered on 21 Dec 2012, 09:53 AM
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.

0
Marc
Top achievements
Rank 1
answered on 30 Dec 2012, 02:11 PM
Updated to Q3 1129. Problem solved! Thank you.
Tags
ListBox
Asked by
Marc
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or