可重复使用的xamarin控件;无法强制转换类型为';Xamarin.forms.xaml.elementnode'&引用;

可重复使用的xamarin控件;无法强制转换类型为';Xamarin.forms.xaml.elementnode'&引用;,xamarin,xamarin.forms,user-controls,reusability,Xamarin,Xamarin.forms,User Controls,Reusability,我是一个noob'ish类型的程序员,这是我第一次尝试在Xamarin.Forms中使用可重用控件(实际上是我所有编程中的第一个)。在研究中,我发现它说我在给一个事件赋值……我很确定它指的是代码的哪一部分……但我不知道该怎么做才能使它正确。我试图制作一个带有标签的ImageCircle,它是一个可重用的控件 我的Xaml: <?xml version="1.0" encoding="UTF-8"?> <ContentView xmlns="http://xamar

我是一个noob'ish类型的程序员,这是我第一次尝试在Xamarin.Forms中使用可重用控件(实际上是我所有编程中的第一个)。在研究中,我发现它说我在给一个事件赋值……我很确定它指的是代码的哪一部分……但我不知道该怎么做才能使它正确。我试图制作一个带有标签的ImageCircle,它是一个可重用的控件

我的Xaml:

       <?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
         x:Class="MyApp.View.Templates.CircleImageButton"
         x:Name="this">
 <ContentView.Content>
    <StackLayout Margin="{StaticResource Margin}" Padding="{StaticResource Padding}" Spacing="0" Grid.Row="{Binding Source={x:Reference this}, Path=GridRow}" Grid.Column="{Binding Source={x:Reference this}, Path=GridColumn}">
        <controls:CircleImage Source="{Binding Source={x:Reference this}, Path=Image}" FillColor="Green" Aspect="AspectFill" Margin="{StaticResource Margin}" >

            <!--error is believed to be caused here-->
<controls:CircleImage.GestureRecognizers>
                <TapGestureRecognizer Tapped="{Binding Source={x:Reference this}, Path=TapGestureCommand}" />
            </controls:CircleImage.GestureRecognizers>

            <controls:CircleImage.WidthRequest>
                <OnPlatform x:TypeArguments="x:Double">
                    <On Platform="Android, iOS">40</On>
                    <On Platform="WinPhone">75</On>
                </OnPlatform>
            </controls:CircleImage.WidthRequest>
            <controls:CircleImage.HeightRequest>
                <OnPlatform x:TypeArguments="x:Double">
                    <On Platform="Android, iOS">40</On>
                    <On Platform="WinPhone">75</On>
                </OnPlatform>
            </controls:CircleImage.HeightRequest>
        </controls:CircleImage>
        <Label Text="{Binding Source={x:Reference this}, Path=LabelCaption}"/>
    </StackLayout>
  </ContentView.Content>
</ContentView>
我感谢你的帮助,如果你有更好的方法,请告诉我。我是来学习的。


<controls:CircleImage.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding Source={x:Reference this}, Path=TapGestureCommand}" />
            </controls:CircleImage.GestureRecognizers>
在XAML中使用命令绑定而不是点击事件

<controls:CircleImage.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding Source={x:Reference this}, Path=TapGestureCommand}" />
            </controls:CircleImage.GestureRecognizers>