Has*_*ruç 25
当标题为空时,则不显示上部栏。像这样:
Title=""
Run Code Online (Sandbox Code Playgroud)
像这样:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Chatfri.Pages.Settings"
Title="">
<StackLayout>
<Label Text="Welcome to Settings!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
如果您使用 shell,则可以使用 Shell.NavBarIsVisible="False"。
<Shell
x:Class="Chatfri.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Chatfri"
xmlns:loc="clr-namespace:Chatfri.Pages"
Shell.FlyoutBehavior="Disabled"
Shell.NavBarIsVisible="False">
<TabBar>
<Tab Icon="home" Title="Home">
<ShellContent
ContentTemplate="{DataTemplate loc:Home}"
Route="Home" />
</Tab>
<Tab Icon="messages" Title="Messages">
<ShellContent
ContentTemplate="{DataTemplate loc:Messages}"
Route="Messages" />
</Tab>
<Tab Icon="settings" Title="Settings">
<ShellContent
ContentTemplate="{DataTemplate loc:Settings}"
Route="Settings" />
</Tab>
</TabBar>
</Shell>
Run Code Online (Sandbox Code Playgroud)
Édg*_*dón 16
不是在 shell 本身中,而是在shell 内显示的页面中,您应该将该Shell.NavBarIsVisible属性设置为 false,如下所示:
<ContentPage
...
Shell.NavBarIsVisible="False" />
Run Code Online (Sandbox Code Playgroud)
您可以阅读文档SetBorderAndTitleBar和Resize:
SetBorderAndTitleBar(Boolean, Boolean) 设置窗口的边框和标题栏属性。
Resize(SizeInt32) 将窗口大小调整为指定大小。
你的 MauiProgram.cs 应该是这样的
using Microsoft.Maui.LifecycleEvents;
#if WINDOWS
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Windows.Graphics;
#endif
namespace YourNameSpace
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
#if WINDOWS
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
window.ExtendsContentIntoTitleBar = false; /*This is important to prevent your app content extends into the title bar area.*/
IntPtr nativeWindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
WindowId win32WindowsId = Win32Interop.GetWindowIdFromWindow(nativeWindowHandle);
AppWindow winuiAppWindow = AppWindow.GetFromWindowId(win32WindowsId);
if(winuiAppWindow.Presenter is OverlappedPresenter p)
{
p.SetBorderAndTitleBar(false, false);
}
const int width = 1200;
const int height = 800;
/*I suggest you to use MoveAndResize instead of Resize because this way you make sure to center the window*/
winuiAppWindow.MoveAndResize(new RectInt32(1920 / 2 - width / 2, 1080 / 2 - height / 2, width, height));
});
});
});
#endif
builder.Services.AddMauiBlazorWebView();
return builder.Build();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但您具体需要的代码是在预处理器指令中找到的代码
#if WINDOWS
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24791 次 |
| 最近记录: |