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

RadListBoxItem and IsKeyboardFocusWithin-IsSelected problem

1 Answer 255 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Zoltan
Top achievements
Rank 1
Zoltan asked on 02 Aug 2012, 10:41 AM
Hello,

I'm using Telerik RadControls for WPF 2012.2.725.40. I have a RadListBox with a DataTemplate for the items. In the DataTemplate I have a TextBox and I want to achieve that when the user clicks inside the TextBox, the ListBoxItem gets selected. So, I made a Style:

<Style TargetType="{x:Type telerik:RadListBoxItem}">
    <Style.Triggers>
        <Trigger Property="IsKeyboardFocusWithin" Value="True">
            <Setter Property="IsSelected" Value="True" />
        </Trigger>
    </Style.Triggers>
</Style>

This works fine with standard WPF ListBox but not with RadListBox/RadListBoxItems.

The full source:
<Window x:Class="IsKeyboardFocusWithin.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <DataTemplate x:Key="ListBoxItemTemplate">
            <TextBox Text="aasdf asdf asdf asdf asf " />
        </DataTemplate>
 
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                    <Setter Property="IsSelected" Value="True" />
                </Trigger>
            </Style.Triggers>
        </Style>
 
        <Style TargetType="{x:Type telerik:RadListBoxItem}">
            <Style.Triggers>
                <Trigger Property="IsKeyboardFocusWithin" Value="True">
                    <Setter Property="IsSelected" Value="True" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
     
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
         
        <ListBox x:Name="lstList" ItemTemplate="{StaticResource ListBoxItemTemplate}" VerticalContentAlignment="Stretch" ItemsSource="{Binding}"
                            SelectionMode="Single" />
 
        <telerik:RadListBox x:Name="lstTelerikList"
                            ItemTemplate="{StaticResource ListBoxItemTemplate}" VerticalContentAlignment="Stretch" ItemsSource="{Binding}"
                            SelectionMode="Single"
                            Grid.Row="1"/>
    </Grid>
</Window>

and the code-behind:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        Items = new ObservableCollection<string>() { "Item 1", "Item 2", "Item 3" };
        InitializeComponent();
        lstList.DataContext = Items;
        lstTelerikList.DataContext = Items;
    }
 
    public ObservableCollection<string> Items
    {
        get;
        set;
    }
}

Am I doing something wrong?

1 Answer, 1 is accepted

Sort by
0
Masha
Telerik team
answered on 03 Aug 2012, 10:52 AM
Hi Zoltan,

There seems to be a problem with IsKeyboardFocusWithin property - it is not updated correctly when the textbox receives the focus. We will research this issue further, for now please use the workaround which we demonstrated in the attached project.

Hope this helps.

Kind regards,
Maria
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ListBox
Asked by
Zoltan
Top achievements
Rank 1
Answers by
Masha
Telerik team
Share this question
or