为什么绑定到一个结构体不起作用? [英] Why Does Binding to a Struct Not Work?

查看:150
本文介绍了为什么绑定到一个结构体不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一个问题,我有一个绑定到ListView一个ObservableCollection。人是我写的结构。只要我设置之前,结合人民的值(S)的对象,一切似乎工作确定。然而,当我尝试设置在运行时从GUI的价值观,似乎底层的对象不以反映更改。

I've recently encountered an issue where I have an ObservableCollection bound to a ListView. People is a structure which I have written. So long as I set the value(s) of the People objects prior to binding, everything seems to work OK. However, when I try to set the values from the GUI at runtime, the underlying objects do not seem to reflect the change.

我终于通过简单地从一种结构改变人们对类克服了这个问题。没有其他的变化是必要的。

I finally overcame this problem by simply changing People from a structure to a class. No other changes were necessary.

可有人请向我解释这是为什么?

Can someone please explain to me why this is?

推荐答案

您结合得到结构的一个副本,因为结构是按值传递给方法。如果绑定更新的东西;在存储器中的拷贝的某处被修改,因此你的原始对象不更新

Your binding gets a copy of struct since structs are passed by value to methods. If the binding updates something; a copy in memory somewhere is being modified and hence the original object of yours is not updated.

这篇关于为什么绑定到一个结构体不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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