【发布时间】:2017-11-24 18:50:12
【问题描述】:
我有一个以 ViewModel 作为 BindingContext 的页面:
public Page()
{
InitializeComponent();
this.BindingContext = new ViewModel();
}
ViewModel 有一个命令:
public class ViewModel : INotifyPropertyChanged
{
...
public ICommand SomeCommand { get; set; }
public ViewModel()
{
SomeCommand = new Command((object data) => {});
}
...
}
在我的 Page.xaml 中,我使用了我的自定义 View 组件,该组件仅用于显示并能够被点击:
<local:CircleView
Radius="20"
InnerText="Click me"
InnerTextSize="15"
TapCommand="{Binding SomeCommand}"
/>
在我的 CircleView.xaml.cs 中
...
public ICommand TapCommand { get; set; }
...
在我的 CircleView.xaml 中:
...
<TapGestureRecognizer
Command="{Binding Path=TapCommand, Source={x:Reference Name=CircleView}}"
CommandParameter="{Binding Path=InnerText, Source={x:Reference Name=CircleView}}"
/>
...
当我运行程序时,我收到错误消息“没有为 TapCommand 找到属性、可绑定属性或事件,或者不匹配...”。如何在 XAML 中传递命令?
【问题讨论】:
-
请注意,这种情况与您在问题中的表述方式略有不同。在您的情况下,您想在用户控件中创建一个可绑定属性。
标签: c# xamarin mvvm xamarin.forms