【发布时间】:2015-03-19 21:07:49
【问题描述】:
我在 XAML 中定义了一个 Button,其中包含一个 Command,其中包括一个 CommandParameter。 Command 绑定到当前视图的 ViewModel,而 CommandParameter 绑定到当前视图中的另一个控件。在 WPF 中,这看起来像:
<TextBox x:Name="MyTextBox" />
<Button Command="{Binding ViewmodelCommand}"
CommandParameter="{Binding ElementName=MyTextBox, Path=Text}" />
根据documentation,在 Xamarin.Forms 视图到视图绑定可以通过使用 x:Reference 标记扩展更改控件的 BindingContext 来实现:
<Button BindingContext="{x:Reference Name=MyTextBox}"
CommandParameter="{Binding Path=Text}" />
但是,在这种情况下,我无法将 Command 绑定到全局 Viewmodel!这种情况有什么解决方案吗?
【问题讨论】:
标签: data-binding xamarin.forms elementname