【发布时间】:2013-07-25 08:08:43
【问题描述】:
我正在开发的应用程序有一种由扩展器组成的手风琴,但每个扩展器独立运行,而不是一次只允许打开一个项目。每个扩展器都与视图模型中集合中的一个项目相关。
我目前的解决方案是使用列表框,然后将列表 itemsource 绑定到集合,并让项目模板呈现扩展器和扩展器内容。
问题在于列表框将每个扩展器视为一个项目(显然)并允许选择和突出显示。突出显示有点难看,可以禁用,但选择会给我带来一些问题,因为它会导致列表滚动以尽可能多地显示展开的扩展器。
是否有一个有点像堆栈面板(也许)的 WPF 控件,它允许我使用项目模板绑定包含的控件,但没有选择和突出显示?
<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>
【问题讨论】:
-
参考这个链接,你可以像下面这样隐藏列表框的选择http://stackoverflow.com/questions/1398559/there-is-no-listbox-selectionmode-none-is-there-another-way -禁用选择
-
我不确定您到底在寻找什么,但
ItemsControl可能就是它。 -
乔恩,这正是我所需要的。我已将列表更改为项目控件(顺便说一句,我的工具箱中未显示),现在我的扩展器按我想要的方式工作。
标签: wpf wpf-controls