は私がBindingContextをとのViewModelとページを持っている:私は表示させるだけで機能します私のカスタムビューコンポーネントを使用して、私のPage.xamlをでXAMLでコマンドを渡すには?
public class ViewModel : INotifyPropertyChanged
{
...
public ICommand SomeCommand { get; set; }
public ViewModel()
{
SomeCommand = new Command((object data) => {});
}
...
}
:
public Page()
{
InitializeComponent();
this.BindingContext = new ViewModel();
}
ViewModelには、コマンドを持っていますそして、クリックする能力があります:私のCircleView.xaml.cs
で<local:CircleView
Radius="20"
InnerText="Click me"
InnerTextSize="15"
TapCommand="{Binding SomeCommand}"
/>
を私CircleView.xamlで
...
public ICommand TapCommand { get; set; }
...
:私はプログラムを実行すると
...
<TapGestureRecognizer
Command="{Binding Path=TapCommand, Source={x:Reference Name=CircleView}}"
CommandParameter="{Binding Path=InnerText, Source={x:Reference Name=CircleView}}"
/>
...
私は「... TapCommandが見つかりませんプロパティ、バインド可能なプロパティ、またはイベント、または不一致」エラーが発生します。 XAMLでコマンドを渡すにはどうすればよいですか?
このシナリオは、あなたの質問でどのように策定されているかとは少し異なります。あなたの場合は、あなたのusercontrolでバインド可能なプロパティを作成する。 – Stefan