簡體   English   中英

Xamarin XamlParseException找不到方法

[英]Xamarin XamlParseException No method found

我的應用程序可以在Visual Studio的Nougat模擬器中正常運行,但是當我將其加載到手機上時將無法啟動並崩潰。 設備日志顯示XamlParseException找不到方法btnIn1_Click。 如果我在后面的代碼中注釋掉btnIn1,除了btnIn2_Click以外,還會給我同樣的錯誤。

我已經在SO上搜索Xamarin應用程序中發生的情況的提示。 我最接近的是: Xmarin.Forms.Xaml.XamlParseException未找到方法

該問題的一個答案是將光標懸停在XAML中的click事件上,然后按F12鍵。 當我這樣做時,我收到消息“無法導航到定義”,該消息告訴我該事件未被識別。

該答案中的解決方案說清理並重建...我已經做過很多次了,但是沒有運氣。

因此,如果有人可以查看我的代碼並確定我所缺少的內容。 這是我的XAML。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:VideoSwitcher"
             x:Class="VideoSwitcher.MainPage"
             Padding="0,20,0,0">

    <Grid BackgroundColor="White"
          Padding="5"
          ColumnSpacing="3"
          RowSpacing="3">
        <Grid.RowDefinitions>
            <RowDefinition Height=".5*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height=".5*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height=".5*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height=".5*"/>
        </Grid.RowDefinitions>
        <Label Grid.Row="0"
               Grid.ColumnSpan="2"
               Text="System Video Switcher"
               TextColor="Black"/>

        <Button Grid.Row="1"
                Grid.Column="0"
                x:Name="btnIn1"
                Text="Input 1"
                BackgroundColor="Firebrick"
                TextColor="White"
                Clicked="btnIn1_Click"/>
        <Button Grid.Row="1"
                Grid.Column="1"
                x:Name="btnIn2"
                Text="Input 2"
                BackgroundColor="Firebrick"
                TextColor="White"
                Clicked="btnIn2_Click"/>
        <Button Grid.Row="3"
                Grid.Column="0"
                x:Name="btnOut1"
                Text="Output 1"
                BackgroundColor="Firebrick"
                TextColor="White"
                Clicked="btnOut1_Click"/>
        <Button Grid.Row="3"
                Grid.Column="1"
                x:Name="btnOut2"
                Text="Output 2"
                BackgroundColor="Firebrick"
                TextColor="White"
                Clicked="btnOut2_Click"/>

        <Button Grid.Row="5"
                Grid.ColumnSpan="2"
                x:Name="btnTake"
                Text="Take"
                BackgroundColor="Firebrick"
                TextColor="White"
                Clicked="btnTake_Click"/>
        <Label Grid.Row="6"
               Grid.ColumnSpan="2"
               TextColor="White"
               x:Name="lblStatus" /> 
    </Grid>

</ContentPage>

在我看來,這是代碼的背后,我的事件定義正確。

using System;
using Xamarin.Forms;
using Enkadia.Extron.Switchers;

namespace VideoSwitcher
{
    public partial class MainPage : ContentPage
    {

        Switcher swt = new Switcher("192.168.2.50", "admin", "******");

        private int Input { get; set; }
        private int Output { get; set; }



        public MainPage()
        {
            InitializeComponent();
            if (swt.IsConnected != true)
            {
                lblStatus.Text = swt.ConnectionError;
            }
        }

        void btnIn1_Click(object sender, EventArgs e)
        {
            Input = 1;
        }

        void btnIn2_Click(object sender, EventArgs e)
        {
            Input = 2;
        }

        void btnOut1_Click(object sender, EventArgs e)
        {
            Output = 1;
        }

        void btnOut2_Click(object sender, EventArgs e)
        {
            Output = 2;
        }

        void btnTake_Click(object sender, EventArgs e)
        {
            swt.RGBXPoint(Input, Output);
        }
    }
}

任何想法歡迎。

您可以通過將iOS項目選項中的“鏈接器行為”更改為“僅鏈接框架SDK”來解決此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM