Unplanned
Last Updated: 03 Aug 2016 13:25 by ADMIN
ADMIN
Kalin
Created on: 26 Mar 2015 11:39
Category: ListBox
Type: Bug Report
2
ListBox: RadListBox placed inside of RadListBoxItem, doesn't lose focus when clicked on the RadListBoxItem.

		
3 comments
ADMIN
Kalin
Posted on: 23 Apr 2015 10:17
Hi David,

I'm pasting my reply from the support ticket here:

If you need to use the custom RadListBoxItem when binding the ItemsSource you would need to implement a custom RadListBox and override the following methods:


public class CustomListBox : RadListBox
{
    protected override DependencyObject GetContainerForItemOverride()
    {
        return new CustomListBoxItem();
    }
 
    protected override bool IsItemItsOwnContainerOverride(object item)
    {
        return item is CustomListBoxItem;
    }
}

Regards,
Kalin
David
Posted on: 09 Apr 2015 14:22
That's fine, but how do you tell the RadListBox to use the CustomRadListBoxItem.

I'm already using ItemTemplates, if that matters in how this is done.
ADMIN
Kalin
Posted on: 09 Apr 2015 11:48
As workaround a custom ListBoxItem can be used instead - the TryFocus method should be overridden as shown below:

public class CustomListBoxItem : RadListBoxItem
{
    protected override void TryFocus()
    {
        var focusedElement = FocusManagerHelper.GetFocusedElement(this) as UIElement;
        if (focusedElement == null ||
            !(focusedElement != this &&
            this.IsAncestorOf(focusedElement) &&
            !(focusedElement is RadListBoxItem)))
        {
            this.Focus();
        }
    }
}

Regards,
Kalin