You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Maui中点击ImageButton跳转至Profile视图的实现方法

.NET Maui中实现ImageButton点击跳转至Profile视图

你可以通过以下两种常见方式实现点击跳转:

方式一:使用传统导航推送

在你的后台点击事件方法中,通过Navigation.PushAsync推送Profile页面实例:

void OnImageButtonClicked(object sender, EventArgs e)
{
    // 实例化Profile页面并推送至导航栈
    Navigation.PushAsync(new Project.Views.Profile());
}

注意:这种方式要求当前页面处于NavigationPage的导航结构中(比如App.xaml.cs中设置主页面为new NavigationPage(new YourMainPage()))。

方式二:使用Shell导航(推荐,若项目基于AppShell)

如果你的项目使用了.NET Maui Shell,先确保在AppShell.xaml中为Profile页面注册路由:

<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:views="clr-namespace:Project.Views"
       x:Class="Project.AppShell">

    <!-- 注册Profile页面路由 -->
    <ShellContent Route="Profile" ContentTemplate="{DataTemplate views:Profile}" />

</Shell>

然后在点击事件中调用Shell的导航方法:

void OnImageButtonClicked(object sender, EventArgs e)
{
    // 通过路由跳转至Profile页面
    Shell.Current.GoToAsync("//Profile");
}

内容的提问来源于stack exchange,提问作者Ilian Gion Häsler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 08:20:32