在 DataTemplate 内显示数据绑定的 StackPanel
我有一些对象正在将数据绑定到 WPF 中的列表框。 最终结果应该是这样的:
------------------------------- | Name | Opt1 | Value1 | | | Opt2 | Value2 | | | Opt3 | Value3 | | | Opt4 | Value4 | -------------------------------
本质上,我有一个用于整个变量的 DataTemplate,然后 Opt/Value 组合有它自己的 DataTemplate。 我试图尽可能简单地显示值列表。
<Label Content="{Binding Path=Identifier.Name, Mode=OneWay}" />
<ListView Grid.Column="1" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Values, Mode=OneWay}" />
Values 的绑定目前只有一个
和 2 个 ,ListView 有很多我不看的功能,例如边框样式、选择等,而我真正想要的是能够使用列表进行数据绑定。
我尝试将项目数据绑定到堆栈面板,但无法使其在 XAML 中工作。 我想另一个解决方案是做我正在做的事情,并重写 ListView 的 。 关于正确的方法有什么建议吗?
I have objects I'm databinding to a ListBox in WPF. Here's what the end result should look like:
------------------------------- | Name | Opt1 | Value1 | | | Opt2 | Value2 | | | Opt3 | Value3 | | | Opt4 | Value4 | -------------------------------
Essentially i've got a DataTemplate for the overall variable, and then the Opt/Value combo has it's own DataTemplate. I'm trying to display the list of values as simply as possible.
<Label Content="{Binding Path=Identifier.Name, Mode=OneWay}" />
<ListView Grid.Column="1" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Values, Mode=OneWay}" />
The binding for Values is currently only a <Grid>
with 2 <Label>
's and ListView has a lot of features I dont watch, such as the border styling, selections, and such, when all I really want is to be able to databind using a List.
I've tried to databind the items to a stackpanel but couldn't get it to work in XAML. I suppose another solution is to do what I'm doing, and rewrite the <Style>
for ListView. Any suggestions on the correct way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来确实像是您可以使用 ListBox,或者 ItemsControl(如果您不希望它们可供选择)。 我们还可以利用 IsSharedSizeScope 附加属性以保持我们的列格式一致。 另外,请查看 ListBox 链接底部的 Inheritance Higharchy,它应该可以帮助您确定不同场景所需的列表类型。
尝试这样的事情:
It certainly sounds like something you can do with a ListBox, or an ItemsControl if you do not want them to be selectable. We can also make use of the IsSharedSizeScope attached property to keep our columns formatted and even. Also, take a look at the Inheritance Higharchy at the bottom of the ListBox link, it should help you determine which type of list you need for different scenarios.
Try something like this: