MVVM Silverlight - 无法将现有控件分配给 XAML 中自定义元素集合的属性
我有一堂课,
public class Item { public string A { get; set; } public Control B { get; set; } }
我正在使用 MVVM 和 Silverlight。我有一个从标准视图继承的自定义视图。自定义视图具有公共属性
public ICollection MyItems { get; set; }which should store items described above.
在我的视图的 xaml 中,
xxxx.MyItems> Item A="someText" B="_existingButton" /> Item A="someText2" B="_existingButton2" /> /xxxx.MyItems>
当尝试为 B 分配值时,View 的 Initialize() 方法失败。
如何为自定义集合项分配对现有元素的引用?
I have a class
public class Item { public string A { get; set; } public Control B { get; set; } }
I'm using MVVM with Silverlight. I have a custom view that is inherited from a standard view. Custom view has public property
public ICollection MyItems { get; set; }
which should store items described above.
In xaml of my view I have
xxxx.MyItems> Item A="someText" B="_existingButton" /> Item A="someText2" B="_existingButton2" /> /xxxx.MyItems>
Initialize() method of View fails when trying to assign value for B.
How can I assign a reference to existing element for a custom collection item?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白您想要实现的目标,但为了帮助您找到解决方案,我建议您首先在代码隐藏文件(即 .xaml.cs)文件中尝试执行您的任务。
通过这样做,您将从编译器和智能感知中获得更多信息帮助。
一旦您在后面的代码中实现了您想要的目标,请尝试在 xaml 文件中实现它。
I don't exactly understand what you are trying to achieve, but to help you arrive at a solution, I recommend that you attempt your task in the code behind file first (i.e. in the .xaml.cs) file.
By doing this, you will be given much more informative help from the compiler and intellisense.
Once you've achieved what you wanted in the code behind, then try and implement it in the xaml file.