问题描述
我有一个的ListView
与的ItemTemplate
包含一个图片
,文本框
,组合框
,的TextBlock
选择任何时候等控制要突出选择的控制而不是整个 ListViewItem的
任何风格就可以了。
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>
任何帮助
推荐答案
你想要的是禁用事件冒泡。当然,它击中控制第一,但click事件冒泡到列表项,太。为了阻止它,你必须把所有的控件的事件处理程序(按钮等),并设置 e.Handled = TRUE
的处理程序,以prevent它会在 ListViewItem的
。
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
.
请参阅:更多信息
如果你从来没有在所有被选择的项目要(很难说你的例子),那么你要使用的代替。这将让你绑定到项目的集合,并显示所有的人,但它没有一个所选项目的概念
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.
这篇关于单独选择一个ListView不是整个ListViewItem的内部控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!