是否有没有选择的 WPF 列表视图之类的东西? [英] Is there something like a WPF listview without the selection?

查看:25
本文介绍了是否有没有选择的 WPF 列表视图之类的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The application I'm developing has a kind of accordion made of expanders but each exapnder acts independently rather than only allowing a single open item at a time. Each expander is related to an item in a collection in the view model.

我目前的解决方案是使用列表框,然后将列表项源绑定到集合,并让项模板呈现扩展器和扩展器内容.

My currently solution is to use a listbox and then bind the lists itemsource to the collection and have an item template render the expander and the exapnders contents.

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

The problem is that the listbox treats each expander as an item (obviously) and allows selection and highlighting. Highlighting is a little ugly and could be disabled, but the selection causes me some issues because it causes the list to scroll to show as much of the expanded expander as possible.

是否有一个有点像堆栈面板(也许)的 WPF 控件,它允许我使用项目模板绑定包含的控件但没有选择和突出显示?

Is there a WPF control that is a little like a stackpanel (perhaps) that would allow me to bind the contained controls using item templating but without the selection and highlighting?

            <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>

推荐答案

如果你想要类似 List 的功能而没有选择功能,你应该使用 ItemsControl - 顺便说一下 Selector 的基类 又是 ListBox

If you want List-like capabilities without selection capabilities, you should use an ItemsControl - incidentally the base class of Selector which in turn is the base class of 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>

显然,在这种情况下您不能绑定选定的项目.

Obviously, you cannot bind a selected item in this case.

这篇关于是否有没有选择的 WPF 列表视图之类的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆