0

そのため、突然、「現在のコンテキストに InitializeComponent という名前が存在しません」という一般的なエラーが、すべてのソリューションのすべての xaml.cs クラスに表示されました。この問題に対して複数の一般的なソリューションを試しましたが、どれも機能していないようです。

Content ビューを継承する xaml.cs:

using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace FirstApp.Renderers
{
    public partial class CustomExpansibleMenu : ContentView
    {
        public CustomExpansibleMenu()
        {
//Error here
            InitializeComponent();
        }
    }
}

コンテンツ ページから継承する xaml.cs:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using FirstApp.Services;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace FirstApp.Pages
{
    public partial class ChatMenuPage : ContentPage
    {
        private NavigationService navigation;
        public static double numPixelsW;
        public static double numPixelsH;

        public ChatMenuPage()
        {
            numPixelsH = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
            numPixelsW = DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density;

            navigation = new NavigationService();

//Error here 
            InitializeComponent();

//Another error here, searchBox is the name of a frame in my xaml page, but //I cant access to it because of the previous error
            searchBox.BorderWith = 3;
        }
    }
}

これらは私が試した一般的な解決策です:

  1. xaml の buildActions が EmbeddedResource に設定されていることを確認します。2) xaml と xaml.cs の名前空間が同じであることを確認します。
  2. xaml で、カスタム ツール: MSBuild:UpdateDesignTimeXaml を確認します。
4

1 に答える 1