我試圖按如下方式將一個集合加載到列表框中(listbox中的一個項目包含一個圖像和一個文本塊)如果我點擊圖像外部的每個項目(區域2)選擇更改正常工作(正確突出顯示);但是如果通過點擊每個圖像來改變選擇,這就需要正確工作。背後的原因是什麼?
逐項WPF listBox集合選擇更改無法正常工作
<DataTemplate x:Key="ObjectGalleryDataTemplate" DataType="{x:Type loc:ObjectTypes}" >
<Button Margin="3" Width="80" Height="80" Click="click_object"BorderBrush="Transparent" Tag="{Binding ObjectTypeID}">
<ItemsPanelTemplate x:Key="ObjectGalleryItemsPanelTemplate">
<UniformGrid Rows="1" HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<Grid><ListBox x:Name="ObjectTypesGallery" SelectionMode="Single" SelectionChanged="objectType_clik" BorderBrush="Transparent" SelectedIndex="0" ItemsSource="{Binding}" ItemTemplate="{DynamicResource ObjectGalleryDataTemplate}" ItemsPanel="{DynamicResource ObjectGalleryItemsPanelTemplate}">
</ListBox>
</Grid>
</StackPanel>
我不明白你想做的事,甚至你的問題是什麼? – Marc
您單擊按鈕事件下面做什麼: 私人無效ButtonBase_OnClick(對象發件人,RoutedEventArgs E) {VAR = curItem( (ListBoxItem)yourList.ContainerFromElement((Button)sender)); curItem.IsSelected = true; } – Aneef