I have the following view model class (based on 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");
}
}
And the following XAML binding:
<Button Command="{Binding AddItem}" Content="{Binding Count}" />
When my view is displayed, the button content is 100 instead of 1. Then when the button is clicked, the content updates to 2, then 3, then 4, etc.
Why is the the first call to SomeList.Add()
not observed?