0
我試圖阻止用戶繼續,直到他們選擇了列表中的至少一個項目。該列表是綁定到主視圖內的單獨視圖控件的,並且列表viewmodel有一個bool,其視圖中的雙向綁定到複選框。繼續命令是主視圖模型的一部分,因此,試圖聽的變化,我創建派生列表訂閱在屬性綁定到複選框的嵌套列表中的更改
tempList = this.WhenAnyValue(x => x.Items,
(layers) => layers == null ? Enumerable.Empty<bool>() : layers.CreateDerivedCollection(x => x.Selected))
.ToProperty(this, x => x.TempList);
CanContinue = this.WhenAnyValue(m => m.CollectionInfo, m => m.TempList,
(collectionDatabase, tempItems) =>
{
if (collectionDatabase == null || tempItems == null) return false;
var temp = tempItems.Any(x => x == true);
return temp;
});
的問題是,TempList永遠不會改變。我可以看到子ViewModel上的Selected屬性發生變化,但就是這樣。
我也曾嘗試分配TempList作爲
tempList = Items.Changed.Select(_ => Items.Select(gr => gr.Selected))
.ToProperty(this, x => x.TempList);
任何人有什麼建議?數據模型超出了我的控制範圍,因爲我正在從磁盤加載包含一組或多組數據的實際應用程序。我有一個sample app,如果你想自己嘗試一下就可以證明這個問題。
我認爲更好的解決方案將NumSelected轉換爲輸出屬性,而不是訂閱和分配使用選擇和ToProperty。 – Ahe