C# 扩展程序和列表视图项行为?
见下图: 单击扩展器中的listbox项并将其保持选中状态,直到您拾取同一列表中的另一项,如果您有单击事件,则不会触发该事件,除非您从同一列表中的项进行更改 请帮忙C# 扩展程序和列表视图项行为?,c#,wpf,C#,Wpf,见下图: 单击扩展器中的listbox项并将其保持选中状态,直到您拾取同一列表中的另一项,如果您有单击事件,则不会触发该事件,除非您从同一列表中的项进行更改 请帮忙 <Grid HorizontalAlignment="Left" Height="420" VerticalAlignment="Top" Width="214"> <ScrollViewer HorizontalAlignm
<Grid HorizontalAlignment="Left" Height="420" VerticalAlignment="Top" Width="214">
<ScrollViewer HorizontalAlignment="Left" Height="420" VerticalAlignment="Top" Width="214">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TreeView Grid.Row="0" Name="treeView1" />
<Expander Grid.Row="1" Header="expander1" Name="expander1" IsExpanded="False">
<ListBox>
<ListBoxItem Content="Unit 1"/>
<ListBoxItem Content="Unit 2"/>
</ListBox>
</Expander>
<Expander Grid.Row="2" Header="expander2" Name="expander2" IsExpanded="False">
<ListBox>
<ListBoxItem Content="Unit 1"/>
<ListBoxItem Content="Unit 2"/>
</ListBox>
</Expander>
</Grid>
这段代码只是为了解释图片中的问题
<Expander Grid.Row="1" Header="expander1" Name="expander1" IsExpanded="False">
<ListBox>
<ListBoxItem Content="Unit 1" PreviewMouseLeftButtonDown="ListBoxItem_PreviewMouseLeftButtonDown"/>
<ListBoxItem Content="Unit 2"/>
</ListBox>
</Expander>
<Expander Grid.Row="2" Header="expander2" Name="expander2" IsExpanded="False">
<ListBox>
<ListBoxItem Content="Unit 1"/>
<ListBoxItem Content="Unit 2" x:Name="listitem1"/>
</ListBox>
</Expander>
现在,另一个列表上的项目返回到正常的“未选定”。如果您的问题没有“?”这是肯定还是问题,我们如何帮助您?请澄清,现在你能帮我吗?我很乐意重读你的出版物,但仍然不理解你的问题。你看了图片吗?你在列表上单击的第一个项目一直单击,直到你在同一列表中单击另一个项目,因此,如果您单击另一个列表中的另一个项目,您将无法返回并单击您在第一个列表中单击的第一个项目,因为它是allready clicket,因此它将不起作用。
private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
listitem1.IsSelected = false;
}