Reputation: 2956
I have a ListView
with ItemTemplate
contains an Image
, TextBox
, ComboBox
, TextBlock
etc when selecting any control should highlight the selected control not the whole ListViewItem
any style would be fine.
<ListView Margin="10" ItemsSource="{Binding TCollection}" SelectedItem="{Binding SelectedTImage}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<Image Width="70" Height="70" HorizontalAlignment="Center">
<Image.Source>
<BitmapImage DecodePixelWidth="300" DecodePixelHeight="300" UriSource="{Binding TImage}"/>
</Image.Source>
</Image>
<TextBox Text="{Binding text}"/>
<TextBlock Text="Contents"/>
<ComboBox/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Any help
Upvotes: 1
Views: 83
Reputation: 15237
What you want is to disable event bubbling. Sure, it hits the control first, but the click event bubbles to the list item, too. In order to stop it, you have to put an event handler on all the controls (button, etc) and set e.Handled = true
in the handler to prevent it from going to the ListViewItem
.
See: disable event-bubbling c# wpf for more info.
If you never want items to be selected at all (hard to tell with your example), then you'd want to use an ItemsControl
instead. That will let you bind to a collection of items and display all of them but it doesn't have the concept of a selected item.
Upvotes: 1