Question

I am trying to bind the Visible property of a MVVMCross Dialog Section.

var refillSection = new Section() {
    new StringElement("Refill").Bind(this, "SelectedCommand OpenExternal")
}.Bind(this, "Visible IsExternal,Converter=Visibility");
root.Add(refillSection);

I have also tried binding the Visible of the Element directly, but does not work either.

var refillSection = new Section() {
    new StringElement("Refill").Bind(this, "SelectedCommand OpenExternal;Visible IsExternal,Converter=Visibility")
};
root.Add(refillSection);

Am I doing something wrong? I have the Visibility plugin installed.

Was it helpful?

Solution

Visible on the Dialog Elements is actually a bool - see https://github.com/slodge/MvvmCross/blob/v3/CrossUI/CrossUI.Touch/Dialog/Elements/Element.cs#L71

Because of this, you don't need to use any Visibility converters when binding to Visible.

Visible itself was recently added to Dialog in this pull request - https://github.com/slodge/MvvmCross/pull/294

As you may be able to see from the discussions on that request, there was some discussion there about how to extend Visible so that it worked for Sections and even for Root. However, sadly I don't think those discussions reached a successful implementation - so I don't believe that the default Section currently works for Visible.

For your specific well-understood scenario for showing/hiding one of your Sections, then I think you might be able to implement this in your app by inheriting and overriding some functionality in Section and possibly also the DialogViewController/DialogAdapter classes. If it helps, one example of Section inheritance is the BindableSection in https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/BindableElements/BindableSection.cs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top