【发布时间】:2015-03-28 01:51:46
【问题描述】:
我有以下视图模型类(基于RxUI design guidelines):
public class SomeViewModel : ReactiveObject
{
private readonly ObservableAsPropertyHelper<int> m_count;
public ReactiveCommand<object> AddItem { get; set; }
public int Count
{
get { return m_count.Value; }
}
public IReactiveList<string> SomeList { get; private set; }
public SomeViewModel ()
{
SomeList = new ReactiveList<string>();
AddItem = ReactiveCommand.Create();
AddItem.Subscribe(x => SomeList.Add("new item"));
m_count = SomeList.CountChanged.ToProperty(this, x => x.Count, 100);
SomeList.Add("first item");
}
}
还有以下 XAML 绑定:
<Button Command="{Binding AddItem}" Content="{Binding Count}" />
显示我的视图时,按钮内容是 100 而不是 1。然后当点击按钮时,内容更新为 2,然后是 3,然后是 4,等等。
为什么没有观察到对SomeList.Add() 的第一次调用?
【问题讨论】:
标签: c# wpf xaml binding reactiveui