RadListBoxItem and IsKeyboardFocusWithin-IsSelected problem

2 posts, 0 answers
  1. Zoltan
    Zoltan avatar
    7 posts
    Member since:
    Feb 2012

    Posted 02 Aug 2012 Link to this post

    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?
  2. Masha
    Admin
    Masha avatar
    355 posts

    Posted 03 Aug 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top