[英]WPF GridViewColumn's DisplayMemberBinding using a Dictionary Key's Value
I haven't found anything similiar to this on Stack or Google, so maybe it isnt' possible, but hopefully someone smart will have an idea.我在 Stack 或 Google 上没有找到与此类似的东西,所以也许不可能,但希望聪明的人会有一个想法。 I'm a bit of a noobie to WPF/XAML.
我对 WPF/XAML 有点陌生。
I have a custom class that resembles something similiar to this.我有一个与此类似的自定义 class。
public class LogEntry
{
public Diciontary<string, string> Stuff;
public string MyOtherProperty;
}
My GridView will have 2 columns.我的 GridView 将有 2 列。 One for MyOtherProperty and one for Stuff["Stuff1"].
一个用于 MyOtherProperty,一个用于 Stuff["Stuff1"]。 Assuming I cannot change the Diciontary to something a lot easier to bind to.
假设我不能将字典更改为更容易绑定的东西。
I am binding my ListView to a List<LogEntry>
.我将我的 ListView 绑定到
List<LogEntry>
。 How would I accomplish it in this scenario.在这种情况下我将如何完成它。
<ListView ItemsSource="{Binding}" DataContext="{Binding}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn DisplayMemberBinding="{Binding MyOtherProperty}"></GridViewColumn>
<GridViewColumn DisplayMemberBinding="**{Binding Stuff[Stuff1]}**"></GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Any ideas?有任何想法吗? Thanks.
谢谢。
WPF supports binding to properties and not fields. WPF 支持绑定到属性而不是字段。 Change LogEntry class to below and it should work.
将 LogEntry class 更改为以下,它应该可以工作。
public class LogEntry
{
public Dictionary<string, string> Stuff { get; set; }
public string MyOtherProperty { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.