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:
This works fine with standard WPF ListBox but not with RadListBox/RadListBoxItems.
The full source:
and the code-behind:
Am I doing something wrong?
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" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 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?