Я обновил пакет xamarin.forms nuget с 3.0.53 до 3.5.0 (да, я пропустил много версий).Но теперь я получаю следующую ошибку в некоторых моих файлах xaml.g.cs
CS0542: 'LocationsView': member names cannot be the sam as their enclosing type
Я знаю, что вы можете изменить имя переменной, изменив поле x: Name в файле xaml, который xaml.g.cs генерируется как показано в следующей ссылке.https://forums.xamarin.com/discussion/129503/after-upgrading-xamarin-forms-from-version-3-0-0-561731-to-3-1-0-583944-i-get-a-compile-error
К сожалению, это не работает для меня, потому что тогда метод FindByName в xaml.g.cs не будет работать, потому что имя не соответствует имени класса, который он пытается найти.Это действительно отстой, потому что не работает в обоих направлениях.
Часть моего файла xaml.g.cs:
[global::Xamarin.Forms.Xaml.XamlFilePathAttribute("Views\\Location\\LocationsView.xaml")]
public partial class LocationsView : global::Views.UserControls.RootPage {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private global::Views.UserControls.RootPage LocationsView;
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(LocationsView));
LocationsView = global::Xamarin.Forms.NameScopeExtensions.FindByName<global::Views.UserControls.RootPage>(this, "LocationsView");
}
}
Часть моего файла xaml:
<UserControls:RootPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Driessen.MijnDriessen.Views.DriessenLocationsView"
xmlns:Behaviors="clr-namespace:Xam.Behaviors;assembly=Xam.Behaviors"
xmlns:UserControls="clr-namespace:MyApp.Views.UserControls;assembly=MyApp"
xmlns:Views="clr-namespace:MyApp.Views;assembly=MyApp"
xmlns:AppFramework="clr-namespace:AppFramework;assembly=AppFramework"
x:Name="LocationsView"
AutomationId="LocationsView"
Title="Locaties">
Есть ли способ обойти ошибку CS50542, чтобы метод FindByName мог по-прежнему выдавать корректный вывод?