SUMMARY: Click on listbox item, textbox in DataTemplate gets focused but listBox Item is not selected.
I'm sure this has something to do with event bubbling but I'm missing something here.
I have ListBox. Each ListBoxItem's ContentTemplate is assigned to a DataTemplate which contains a simple textbox.
This TextBox is designed to appear as a fake editable label.
Problem: When clicking on the textbox, the selectedItem of the ListBox is not being updated. The textbox is swallowing the mousedown event and the listbox is never notified to update to the new item.
I feel like I'm missing something stupid here. Any ideas? Is there a way to force the event to bubble up to the parent ListView?
I've tried everything from making the textbox's background Null to handling the previewmousedown event and setting e.handled = false;.
DataTemplate:
<DataTemplate x:Key="ItemTempl">
<TextBox Height="20" Width="200" Name="tbox" Text="{Binding WordText}" HorizontalAlignment="Stretch">
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="{x:Null}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsFocused, ElementName=tbox}" Value="True">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Background" Value="White"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DataTemplate>
Listview:
<ListView HorizontalAlignment="Stretch" ItemsSource="{Binding Something.Words}" Name="MainListView" SelectedItem="{Binding CurrentItem, Mode=TwoWay}" BorderThickness="0" ItemContainerStyle="{StaticResource ContainerStyle}">
</ListView>
ItemTempl
in your ListView. You also didn't explain whatContainerStyle
is. – Blachshma