筹集的财产更改为ViewModel之外的财产
使用MVVMCROSS,FWIW I具有一个ViewModel,其主要是为了轻松XAML绑定目的而创建的几个属性。例如:
public int HomeScore
{
get { return Contest.Team[HomeID].Score; }
}
homescore绑定到XAML视图中的文本块。 比赛是一个单身班,其中包含一个由两个团队组成的词典团队,HomeID代表其中一个钥匙。该值是一类TeamStats,其中包含属性整数得分。 当前的困境 /挑战是当另一种方法更新分数时,该通知应该如何传递到ViewModel,然后将视图传递给显示屏中的更新分数。 我已经玩过MVVMCross SetProperty和Raisepropertychang,但无济于事。
Using MvvmCross, fwiw I have a ViewModel with several properties created primarily for ease XAML binding purposes. For example:
public int HomeScore
{
get { return Contest.Team[HomeID].Score; }
}
HomeScore is bound to a TextBlock in the XAML view.
Contest is a singleton class that contains a dictionary Team of two teams, HomeID representing one of the Keys. The value is a class of TeamStats, that contains a property integer Score.
The current dilemma / challenge is when another method updates the Score, how should that notification get passed on to the ViewModel and subsequently the View to show the updated score in the display.
I've played around with the MvvmCross SetProperty and RaisePropertyChanged at various levels but all to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果团队的“得分”属性本身出版/提高了房地产,则需要倾听它,并且在任何更改后都需要换取“ HomeScore”的财产。
顺便说一句,如果您丢弃便利包装的“ HomeScore”,然后将属性路径直接放入XAML中,则无需做任何事情。
WPF将绑定完整的路径,包括自动化的更改侦听器。 Afaik可以处理字典索引器。
XAML
(HOMEID可能应由其实际价值代替)。
**
更新:
演示,用于绑定静态类词典 **
xaml window1.xaml
cs:window1.xaml.cs
+ VM背后的代码
If the Team's "Score" property itself publishes/raises PropertyChanged, you need to listen to it and on any change raise PropertyChanged for "HomeScore".
By the way, if you discard the convenience wrapper "HomeScore" and put the property path directly in XAML, you don't have to do anything.
WPF would bind the complete path including the change listeners automagically. Afaik it can handle the dictionary indexer.
XAML
(HomeID should likely be replaced by its actual value).
**
Update:
Demo for Binding to a dictionary of a static class**
XAML Window1.xaml
CS: Window1.xaml.cs
Code behind + VM