2012-09-03 56 views
1

此問題完整的源可以在這裏找到:https://github.com/Cheesebaron/MvvmCross.SettingsSampleMvvmCross:雙向綁定與MonoTouch.Dialog

我的主要關注在於SettingsView,在那裏我嘗試綁定一些簡單的BooleanElements:

this.Root = new RootElement("Settings") 
      { 
       new Section("Test", string.Format("Choose to see your own location on the map.{0}Choose to allow shake gestures.{0}Choose whether you want to receive notifications.", Environment.NewLine)) 
       { 
        new BooleanElement("Show my location", ViewModel.ShowMyLocation).Bind(this, "{'Value':{'Path':'ShowMyLocation','Mode':'TwoWay'}}"), 
        new BooleanElement("Shake gestures", ViewModel.ShakeGestures).Bind(this, "{'Value':{'Path':'ShakeGestures','Mode':'TwoWay'}}"), 
        new BooleanElement("Notifications", ViewModel.Notifications).Bind(this, "{'Value':{'Path':'Notifications','Mode':'TwoWay'}}"), 
       }, 
      }; 

我的問題在於,綁定似乎只有一種方式,即使我明確指定它是TwoWay。雙向綁定似乎在WP7和Android上運行良好,所以我知道視圖模型是可以的。但是,我錯過了一些代碼,用於雙向綁定或者框架中的某些錯誤或缺失。

如果我嘗試使用其他類型的元素,例如CheckboxElementStyledStringElement,此問題也存在。也是我自己做的元素...

+0

感謝您的示例。對於布爾示例,我猜這肯定是個bug。可能是我在https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross.Dialog/MvxTouchDialogBindingSetup.cs中包含錯誤的類 - 也許CheckboxElement需要是BaseBooleanElement。對於StyledStringElement,我不確定 - 我真的不明白如何使StyledStringElement可編輯?今晚我會回頭看看蘋果機。 – Stuart

+0

啊,等一下。 StyledStringElement的作品,但它就像視圖不會自行更新。所以如果你點擊它更新的單元格。因此,出於某種原因,該單元未被通知變化。 (另一個問題?) – Cheesebaron

+0

仍然看着這個(更新XCode和Monotouch和...),但與StyledStringElement我想知道重繪需要強制使用cell.SetNeedsDisplay(也許cell.Backbground.SetNeedsDisplay呢?)。更新完成後,請看這個。 – Stuart

回答

1

按照上述意見,這種感覺就像這是幾個不同的問題:

感謝您報告這些問題 - 以及與測試用例跟進。我會看看是否可以解決如何在mvx存儲庫中包含一些更正式的測試用例。


作爲將來的一項工作,我也想挺喜歡形式化ValueValueChanged關係 - 我認爲可以提供一般的規則,以便與價值的ValueChanged和所有元素將支持數據綁定 - 添加問題https://github.com/slodge/MvvmCross/issues/26