Reputation: 24460
Full source for this issue can be found here: https://github.com/Cheesebaron/MvvmCross.SettingsSample
My main concern lies in the SettingsView, where I try to bind some simple 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'}}"),
},
};
My problem resides in that the bindings only seem to work one way, even though I explicitly specify that it is TwoWay
. The two way bindings seem to work fine on WP7 and Android, so I know the view model is ok. But either I am missing some code for the two way bindings or something is wrong or missing in the framework.
This issue is also there if I try with other types of elements like CheckboxElement
or StyledStringElement
. Also my own made elements...
Upvotes: 1
Views: 1124
Reputation: 66882
Following the comments above, this feels like this is a few separate problems:
the BooleanElement wasn't correctly linked into MvxTouchDialogBindingSetup.cs - I have hopefully now fixed this - see this commit - https://github.com/slodge/MvvmCross/commit/38e5f08acaffa6ac76d060d104f841f2765d234c - tested with your test project
the StyledStringElement may simply need a "kick" to force it to redraw - so we may need to call cell.SetNeedsDisplay()
- and maybe also cell.Backbground.SetNeedsDisplay()
- I don't have a test case for this at present.
your new cells may need to be linked in using new binding entries in your Setup.cs
Thanks for reporting these issues - and for following up with a test case. I will see if I can work out how to include some more formal test cases within the mvx repository.
As a future work item, I'd also quite like to formalise the Value
and ValueChanged
relationship - I think a general rule can be provided so that all Elements with Value and ValueChanged will support databinding - added as issue https://github.com/slodge/MvvmCross/issues/26.
Upvotes: 1