是否有类似于没有选择的WPF listview的东西?

是否有类似于没有选择的WPF listview的东西?,wpf,wpf-controls,Wpf,Wpf Controls,我正在开发的应用程序有一种由扩展器制成的手风琴,但每个测试仪都独立工作,而不是一次只允许一个打开的项目。每个扩展程序都与视图模型中集合中的一个项相关 我目前的解决方案是使用listbox,然后将lists itemsource绑定到集合,并使用一个项目模板呈现expander和exapnders内容 问题是列表框将每个扩展器视为一个项目(显然),并允许选择和突出显示。突出显示有点难看,可能会被禁用,但选择会给我带来一些问题,因为它会导致列表滚动以尽可能多地显示扩展的扩展器 是否有一个WPF控件有

我正在开发的应用程序有一种由扩展器制成的手风琴,但每个测试仪都独立工作,而不是一次只允许一个打开的项目。每个扩展程序都与视图模型中集合中的一个项相关

我目前的解决方案是使用listbox,然后将lists itemsource绑定到集合,并使用一个项目模板呈现expander和exapnders内容

问题是列表框将每个扩展器视为一个项目(显然),并允许选择和突出显示。突出显示有点难看,可能会被禁用,但选择会给我带来一些问题,因为它会导致列表滚动以尽可能多地显示扩展的扩展器

是否有一个WPF控件有点像stackpanel(也许),它允许我使用项模板绑定包含的控件,但不需要选择和突出显示

            <ListBox Grid.Row="0" Grid.Column="0" Width="Auto" SelectionMode="Single" ItemsSource="{Binding Path=MeasurementSources}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Expander  Header="{Binding Name}" IsEnabled="{Binding Available}">
                        <ListBox Width="Auto" SelectionMode="Single"
                                ItemsSource="{Binding Path=Measurements}"
                                SelectedItem="{Binding Path=SelectedMeasurement}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <WrapPanel>
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                                        <TextBlock Text=" "/>
                                        <TextBlock Text="{Binding Created}"/>
                                    </WrapPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Expander>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>



最好的解决方案是:

 <Style TargetType="{x:Type ListBoxItem}">
      <Style.Resources>
          <!-- With focus -->
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                                 Color="Transparent" />
          <!-- Without focus -->
          <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                                 Color="Transparent" />
          <!-- Text foreground -->
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
                                 Color="Black" />
      </Style.Resources>
      <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
</Style>


几个月前,我在
stackoverflow
:)

上发现了它,如果您想要类似列表的功能而不需要选择功能,那么应该使用
ItemsControl
——顺便提一下,
Selector
的基类是
ListBox

然后整个事情就变成了

<ItemsControl Width="Auto" ItemsSource="{Binding Measurements}"
  <ItemsControl.ItemTemplate>
    <DataTemplate>
      <WrapPanel>
        <TextBlock Text="{Binding Name}" FontWeight="Bold" />
        <TextBlock Text=" "/>
        <TextBlock Text="{Binding Created}"/>
      </WrapPanel>
    </DataTemplate>
 </ItemsControl.ItemTemplate>
</ItemsControl>

这是一条我没有意识到的有用信息

注意ItemsControl是几个常见集合的基类 控件,包括ListView、GridView、FlipView、ListBox和 组合框控件。这些示例使用ListView和GridView 控件,但该信息通常应用于ItemsControl


换句话说,使用ItemsControl确实是解决我的问题的方法,因为使用列表框,然后尝试禁用突出显示和选择功能,实际上是将其返回到自己的基类中。

请参阅此链接,您可以像这样隐藏列表框的选择belowhttp://stackoverflow.com/questions/1398559/there-is-no-listbox-selectionmode-none-is-there-another-way-to-disable-selectI 我不确定你到底在找什么,但可能是。乔恩,那正是我需要的。我已经将列表更改为itemscontrol(顺便说一句,它没有显示在我的工具箱中),现在我的扩展器以我想要的方式工作。Mateusz,我想这可能是一个解决方案,但我更喜欢Jon提出的使用itemscontrol的解决方案。它只是给我所有我需要的行为,而不需要禁用我不需要的行为。但是谢谢你的回答。是的,我想你和乔恩已经一针见血了。这是我需要的ItemsControl。