我正在尝试绑定MVVMCross对话框部分的Visible属性。
var refillSection = new Section() {
new StringElement("Refill").Bind(this, "SelectedCommand OpenExternal")
}.Bind(this, "Visible IsExternal,Converter=Visibility");
root.Add(refillSection);
我也试过直接绑定元素的可见性,但也不起作用。
var refillSection = new Section() {
new StringElement("Refill").Bind(this, "SelectedCommand OpenExternal;Visible IsExternal,Converter=Visibility")
};
root.Add(refillSection);
我做错了吗?我安装了Visibility插件。
答案 0 :(得分:2)
Visible
上的 Element
实际上是bool
- 请参阅https://github.com/slodge/MvvmCross/blob/v3/CrossUI/CrossUI.Touch/Dialog/Elements/Element.cs#L71
因此,绑定到Visibility
时,您无需使用任何Visible
转换器。
Visible
本身添加到Dialog - https://github.com/slodge/MvvmCross/pull/294
正如您可以从有关该请求的讨论中看到的,有一些关于如何扩展Visible
的讨论,以便它适用于Section
甚至Root
。但遗憾的是,我认为这些讨论没有成功实施 - 因此我认为默认Section
目前不适用于Visible
。
对于您显示/隐藏其中一个Section
的具体易懂的方案,我认为可能能够通过继承和覆盖某些功能在您的应用中实现此功能在Section
中,也可能在DialogViewController
/ DialogAdapter
类中。如果有帮助,Section
继承的一个示例是https://github.com/slodge/MvvmCross-Tutorials/blob/master/DialogExamples/DialogExamples.Touch/BindableElements/BindableSection.cs中的BindableSection