简体   繁体   English

WPF GridViewColumn 的 DisplayMemberBinding 使用字典键的值

[英]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.

相关问题 如何在代码中绑定GridViewColumn的DisplayMemberBinding - How to bind GridViewColumn's DisplayMemberBinding in code WPF:对GridViewColumn中的DisplayMemberBinding使用PriorityBinding - WPF: Use PriorityBinding for DisplayMemberBinding in GridViewColumn WPF - 使用 DisplayMemberBinding 将工具提示添加到 GridViewColumn - WPF - Adding a Tooltip to a GridViewColumn with DisplayMemberBinding 使用wpf在列表框中绑定字典的键和值 - Binding a Dictionary's key and value in a listbox with wpf WPF GridViewColumn DisplayMemberBinding绑定到object =&gt;空字符串。 为什么/ - WPF GridViewColumn DisplayMemberBinding bound to an object => empty string. Why/ 如何在WPF中隐藏GridViewColumn好像它在运行时折叠一样? - How to hide a GridViewColumn as if it's collapsed at runtime in WPF? 在WPF StackPanel GridViewColumn中将外键表示为其他值 - Representing a Foreign Key as some other value in a WPF StackPanel GridViewColumn 如何在WPF中通过其标题名称获取GridViewColumn? - How to get a GridViewColumn by its header's name in WPF? Sortedlist/Dictionary 在索引处修改键的值 - Sortedlist/Dictionary modify a key's value at an index 搜索字典值的字符串,然后用字典的键替换匹配的值? - Search string for Dictionary Value, then replace matched value with Dictionary's key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM