Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.forms 图像标签识别器未启动_Xamarin.forms - Fatal编程技术网

Xamarin.forms 图像标签识别器未启动

Xamarin.forms 图像标签识别器未启动,xamarin.forms,Xamarin.forms,我真的不明白为什么这个图像录制识别器没有启动 <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MainMenu"> <Con

我真的不明白为什么这个图像录制识别器没有启动

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MainMenu">   

    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness"
                iOS="0, 20, 0, 0"
                Android="0, 0, 0, 0"
                WinPhone="0, 0, 0, 0" />
    </ContentPage.Padding>

    <ContentPage.Content>

        <Grid>

            <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" RowSpacing="0">

                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <BoxView BackgroundColor="AliceBlue" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="5"/>
                <Image Source="itemIcon1" Grid.Row="0" Grid.Column="0" Aspect="AspectFit" BackgroundColor="Transparent" WidthRequest="30" HeightRequest="30" />
                <Label Text = "Cpyname" FontSize="16" Grid.Row="0" Grid.Column="1"  Grid.ColumnSpan="2"/>


                <Grid Grid.Row="1">

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width ="200"/>
                            <ColumnDefinition Width ="10"/>
                            <ColumnDefinition Width ="200"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>


                        <Grid Grid.Row="0" Grid.ColumnSpan="3">
                            <StackLayout  HeightRequest="80" Orientation="Horizontal">
                            </StackLayout>
                        </Grid>



                        <StackLayout Grid.Row="1" Grid.Column="0" WidthRequest="110" Orientation="Vertical">
                            <Image x:Name="ImgRepairSvc" Source="M1.png" HeightRequest="100" WidthRequest="100"/>
                        </StackLayout>

                        <StackLayout Grid.Row="1" Grid.Column="2" WidthRequest="110" Orientation="Vertical">
                            <Image Source="M2.png" HeightRequest="100" WidthRequest="100"/>
                        </StackLayout>


                    </Grid>
                </Grid>

            </Grid>
        </Grid>

    </ContentPage.Content>
</ContentPage>

代码如下:

1) XAML :

 <StackLayout Grid.Row="1" Grid.Column="0" WidthRequest="110" Orientation="Vertical">
   <Image x:Name="ImgSvc" Source="M1.png" HeightRequest="100" WidthRequest="100"/>  
</StackLayout>


2) Code behind the XAML:

public MainMenu 
{           
     InitializeComponent ();            
     SetUp();

}


 void SetUp()
 {

    ImgSvc.GestureRecognizers.Add(new TapGestureRecognizer()
    {
       Command = new Command(TapCallback)

    });

  }


  private void TapCallback()
  {
     DisplayAlert("Tap", "This is image Tap", "Ok");

  }
1)XAML:
2) XAML背后的代码:
公共主菜单
{           
初始化组件();
设置();
}
无效设置()
{
添加(新的TapGestureRecognizer())
{
命令=新命令(TapCallback)
});
}
私有void TapCallback()
{
DisplayAlert(“点击”,“这是图像点击”,“确定”);
}
在Emulator(Droid)上编译成功,但当使用鼠标单击图像时,没有显示警报

谢谢你的帮助


谢谢

我认为这不能正常工作的主要原因是您使用的所有
网格
堆栈布局
控件的混乱结构。您有一个网格,其列的
宽度设置为40。在该列中,您将添加一个
网格
,该网格有一个
宽度为200的列和一个
图像
宽度为110的列。您可以在此图像中看到它:

当我单击
图像
(红色)时,
标签识别器
仅在单击紫红色
网格
元素内图像的左侧部分时触发。在
图像的父级之外渲染的所有外部内容都不会触发
TapGestureRecognitor

我的建议是清理您的XAML,因为我无法想象您创建的布局需要如此复杂的嵌套
StackLayout
Grid
控件。

下面是为每个元素设置背景色的代码,以防您想亲自查看

 <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness"
                iOS="0, 20, 0, 0"
                Android="0, 0, 0, 0"
                WinPhone="0, 0, 0, 0" />
    </ContentPage.Padding>
    <ContentPage.Content>
        <Grid BackgroundColor="Yellow">
            <Grid BackgroundColor="Blue" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" RowSpacing="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <BoxView BackgroundColor="AliceBlue" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="5"/>
                <Image BackgroundColor="Olive" Source="itemIcon1" Grid.Row="0" Grid.Column="0" Aspect="AspectFit" WidthRequest="30" HeightRequest="30" />
                <Label BackgroundColor="Gray" Text = "Cpyname" FontSize="16" Grid.Row="0" Grid.Column="1"  Grid.ColumnSpan="2"/>

                <Grid Grid.Row="1" BackgroundColor="Teal">
                    <Grid BackgroundColor="Fuchsia">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="200"/>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition Width="200"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <Grid BackgroundColor="Lime" Grid.Row="0" Grid.ColumnSpan="3">
                            <StackLayout HeightRequest="80" Orientation="Horizontal">
                            </StackLayout>
                        </Grid>

                        <StackLayout BackgroundColor="Maroon" Grid.Row="1" Grid.Column="0" WidthRequest="110" Orientation="Vertical">
                            <Image x:Name="ImgRepairSvc" BackgroundColor="Red" Source="M1.png" HeightRequest="100" WidthRequest="100"/>
                        </StackLayout>

                        <StackLayout BackgroundColor="Purple" Grid.Row="1" Grid.Column="2" WidthRequest="110" Orientation="Vertical">
                            <Image Source="M2.png" HeightRequest="100" WidthRequest="100"/>
                        </StackLayout>
                    </Grid>
                </Grid>
            </Grid>
        </Grid>
    </ContentPage.Content>


您是否已将断点放在
点击回调
中,并且没有停止断点,或者只是无法看到警报?单击emulator中的图像时,什么也没有发生。甚至我也在TapCallback中设置了断点。在emulator上测试时点击是否与单击相同?请显示布局的其余部分,您可能与图像重叠。为元素提供背景色和/或将
InputTransparent
属性设置为truecan@Gerald请查看整个页面的更新。您是否有一个
公共ICommand TapCommand{
返回您的命令对象?@两个:Steven和Gerald,谢谢。您的建议有效。我清理了布局并尝试了一下。有效。