我想学习如何将 的MainPage
属性设置App
为MyPage
从ContentPage
. 在App.xaml.cs
它可以很容易地完成如下。
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MyPage();
}
}
如何在 XAML 中做同样的事情?
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
mc:Ignorable="d"
x:Class="MyProject.App">
<!-- Others have been removed only for simplicity! -->
<Application.MainPage>
<!-- I don't know what I have to do here. -->
</Application.MainPage>
</Application>
你需要声明一个本地命名空间
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
mc:Ignorable="d"
xmlns:local="clr-namespace:MyNamespace"
x:Class="MyProject.App">
<Application.MainPage>
<local:MyPage />
</Application.MainPage>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句