English 中文(简体)
• 如何用MAUI替换一页?
原标题:How do you replace a page with another in MAUI?
  • 时间:2023-12-18 16:31:31
  •  标签:
  • maui

我有一页的标识,首先出现在我的MAUI仪器运行之时。 在登录后,I navigate to the dash板 page but myuser can press the Backutton to re to thelogin page.

是否在把 log印页打到仪表板页之后,可以关闭标识页,从而把仪表板的页子变成根基?

在安伯,我将去做仪表板的活动,并在标识页上执行“定点”。

总之,我的问题有多种形式:

  1. Is there a way to replace one page with another?
  2. Is there a way to make a page become the new root page?
  3. Is there a way to remove a root page from the navigation stack?
问题回答

你可以援引以下法典:

• 创建MAUI项目,然后将LoginPage和NewPage1增到根名录,并在LoginViewModel内部添加观点模块:

“在此处的影像描述”/</a

伐木 页: 1

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp5.LoginPage"
             Title="LoginPage">

    <VerticalStackLayout>
        <Label
            Text="Welcome to .NET MAUI!"
            VerticalOptions="Center"
            HorizontalOptions="Center" />
        <Button Text="Login"  
                Command="{Binding LoginCommand}"/>
    </VerticalStackLayout>
</ContentPage>
public partial class LoginPage : ContentPage
{
    public LoginPage()
    {
        InitializeComponent();
        this.BindingContext = new LoginViewModel();
    }
}

LoginViewModel:

public class LoginViewModel
{
    public Command LoginCommand { get; }

    public LoginViewModel () { LoginCommand = new Command (OnLoginClicked); }

    private async void OnLoginClicked (object obj)
    {
         await Shell.Current.GoToAsync ($"//{nameof(MainPage)}");
    }
}

为返回LoginPage而增加一个县:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp5.MainPage">

   <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

           .....

           <Button Text="LoginPage" Clicked="Button_Clicked"/>

       </VerticalStackLayout>
    </ScrollView>

</ContentPage>
public partial class MainPage: ContentPage 
{
  int count = 0;

  public MainPage() 
  {
    InitializeComponent();
  }
  
  ....
  
  private void Button_Clicked(object sender, EventArgs e) 
  {
    Shell.Current.GoToAsync($"//{nameof(LoginPage)}");
  }
}

AppShell.xaml:

<Shell
    x:Class="MauiApp5.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MauiApp5"
    Shell.FlyoutBehavior="Disabled">


   <ShellContent Title="LoginPage" Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" Shell.TabBarIsVisible="False"/>
    
    <FlyoutItem >
        <ShellContent Title="Home" Route="MainPage" ContentTemplate="{DataTemplate local:MainPage}" />
        <ShellContent Title="NewPage1" Route="NewPage1" ContentTemplate="{DataTemplate local:NewPage1}" />
    </FlyoutItem>

</Shell>

这里是effect





相关问题
Unable to access file in ResourcesSounds folder

I m using .net Maui and attempting to create audioManager players for a couple of sound files located in the ResourcesSounds folder in the project. The code is this: var playerStartSound = ...

.NET MAUI native audio player

I am interested is there a way to play mp3 files from the phone internal memory using the built in native audio player. I am asking this, because I want to implement an equalizer too, so I am guessing ...

Integrating Push Notifications in MAUI .NET 7 Applications

I m developing a cross-platform application using MAUI .NET 7 and I would like to add push notification functionality to my application. I m considering using Firebase Cloud Messaging or Azure ...

Databinding doesnt work in my xaml.cs file

I am trying to load some data from my Model to the xaml.cs file. But it doesn t work. In my Mainpage.xaml i have a binding property inside a label. In the code behind file a BindingContext to my ...

Do some tasks after OnAppearing() in MAUI

I have a maui community toolkit expander control in my page. On Tapping the header the content is shown/hidden .I got a Maui map in the expander s content. It display properly if the expander is in ...

NET MAUI是否有可调整的分辨率特征?

页: 1 NET MAUI用于一个即将到来的项目,但我发现一件失踪的事情是,我需要的是分裂的特征。 我发现,散射器在移动上可能不会产生作用,但Im主要针对Windows......。

How to optimize detail page reset button in C# MAUI?

I ve implemented a Reset button on a Detail page in C# MAUI and it works, but I can t figure out why I need to be so explicit in the way I capture the initial data to perform the reset, when requested....

热门标签