我在我的Xamarin.Forms项目中遇到了一个问题,我正在寻求帮助解决它.我遇到以下错误:
Severity Code Description Project File Line Suppression State Error CS0263 Partial declarations of 'App' must not specify different base classes BeautyFly C:\Users\lenovo\Desktop\BeautyFly\BeautyFly\BeautyFly\App.xaml.cs 9 Active
此外,还有一个相关的错误:
Severity Code Description Project File Line Suppression State Error CS0103 The name 'MainPage' does not exist in the current context BeautyFly C:\Users\lenovo\Desktop\BeautyFly\BeautyFly\BeautyFly\App.xaml.cs 19 Active
Context:个
项目 struct :
名为"BeautyFly"的Xamarin.Forms项目
App.xaml.cs文件包含App类定义
应用程序主页的MainPage.xaml和MainPage.xaml.cs文件
代码片段:
App.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"
x:Class="BeautyFly.App">
<StackLayout>
<Entry x:Name="resultEntry" Text="0" HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand" FontSize="30" HorizontalTextAlignment="End"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Text="7" Clicked="OnNumberClicked" Grid.Row="1" Grid.Column="0" />
<Button Text="8" Clicked="OnNumberClicked" Grid.Row="1" Grid.Column="1" />
<Button Text="9" Clicked="OnNumberClicked" Grid.Row="1" Grid.Column="2" />
<Button Text="/" Clicked="OnOperatorClicked" Grid.Row="1" Grid.Column="3" />
<Button Text="4" Clicked="OnNumberClicked" Grid.Row="2" Grid.Column="0" />
<Button Text="5" Clicked="OnNumberClicked" Grid.Row="2" Grid.Column="1" />
<Button Text="6" Clicked="OnNumberClicked" Grid.Row="2" Grid.Column="2" />
<Button Text="*" Clicked="OnOperatorClicked" Grid.Row="2" Grid.Column="3" />
<Button Text="1" Clicked="OnNumberClicked" Grid.Row="3" Grid.Column="0" />
<Button Text="2" Clicked="OnNumberClicked" Grid.Row="3" Grid.Column="1" />
<Button Text="3" Clicked="OnNumberClicked" Grid.Row="3" Grid.Column="2" />
<Button Text="-" Clicked="OnOperatorClicked" Grid.Row="3" Grid.Column="3" />
<Button Text="0" Clicked="OnNumberClicked" Grid.Row="4" Grid.Column="0" />
<Button Text="." Clicked="OnDecimalClicked" Grid.Row="4" Grid.Column="1" />
<Button Text="=" Clicked="OnEqualClicked" Grid.Row="4" Grid.Column="2" />
<Button Text="+" Clicked="OnOperatorClicked" Grid.Row="4" Grid.Column="3" />
</Grid>
</StackLayout>
</ContentPage>
App.xaml.cs:
using BeautyFly.Services;
using BeautyFly.Views;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace BeautyFly
{
public partial class App : Application
{
private string currentInput = string.Empty;
private string currentOperator = string.Empty;
private double result = 0;
public App()
{
InitializeComponent();
DependencyService.Register<MockDataStore>();
MainPage = new AppShell();
}
private void OnNumberClicked(object sender, EventArgs e)
{
Button button = (Button)sender;
currentInput += button.Text;
resultEntry.Text = currentInput;
}
private void OnOperatorClicked(object sender, EventArgs e)
{
Button button = (Button)sender;
currentOperator = button.Text;
result = double.Parse(currentInput);
currentInput = string.Empty;
}
private void OnEqualClicked(object sender, EventArgs e)
{
double secondOperand = double.Parse(currentInput);
switch (currentOperator)
{
case "+":
result += secondOperand;
break;
case "-":
result -= secondOperand;
break;
case "*":
result *= secondOperand;
break;
case "/":
if (secondOperand != 0)
result /= secondOperand;
else
resultEntry.Text = "Error";
break;
}
resultEntry.Text = result.ToString();
currentInput = string.Empty;
}
private void OnDecimalClicked(object sender, EventArgs e)
{
if (!currentInput.Contains("."))
{
currentInput += ".";
resultEntry.Text = currentInput;
}
}
}
}
采取的故障排除步骤:
已判断App类的继承 已验证MainPage类及其引用
Questions:个
是什么原因导致我的App.xaml.cs文件中出现"‘App’的部分声明不能指定不同的基类"错误?
如何解决"当前上下文中不存在主页面名称"的错误?
我的代码中是否有需要判断的特定区域来确定和解决此问题?
如有任何指导或建议,我们将不胜感激.谢谢!