如何在 MAUI 中设置窗口大小?
背景信息:我只关心此应用程序的 Windows - 我选择了 MAUI,因此我可以将 Blazor 用于桌面应用程序。由于某种原因,默认窗口尺寸很大(几乎占据了我所有的 1440p 屏幕空间)。我正在制作的应用程序只需要大约 600x600。尽管我很高兴让应用程序能够响应,但有一种方法可以固定窗口大小也会很有帮助。
将我的视图绑定到视图模型时发生。
错误描述:
System.MissingMethodException: 'No parameterless constructor defined for type 'yournamespace.view.pagename'.'
Run Code Online (Sandbox Code Playgroud) 是否可以在MAUI项目中使用WinUI 3现有的控件?就像https://github.com/microsoft/WinUI-Gallery中的控件一样
我将 WinUI 包安装到我的 MAUI 项目中
<ItemGroup>
<PackageReference Include="Microsoft.UI.Xaml" Version="2.7.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.1" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
并编辑App.xaml
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiWithWinui"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:Class="MauiWithWinui.App">
<Application.Resources>
<controls:XamlControlsResources>
<controls:XamlControlsResources.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</controls:XamlControlsResources.MergedDictionaries>
</controls:XamlControlsResources>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
也 Platform/Windows/App.xaml
<maui:MauiWinUIApplication
x:Class="MauiWithWinui.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:MauiWithWinui.WinUI"
xmlns:controls="using:Microsoft.UI.Xaml.Controls">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>
</maui:MauiWinUIApplication>
Run Code Online (Sandbox Code Playgroud)
但是当我去MAUI的某个Page下使用WinUI控件时,提示找不到该控件
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:Class="MauiWithWinui.MainPage">
<Grid>
<controls:RatingControl AutomationProperties.Name="RatingControl with placeholder" PlaceholderValue="3" />
</Grid>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
MAUI项目仅针对Windows平台,尽管我知道winui3项目是更好的选择
如何使 .net MAUI 应用程序在启动时最大化 Windows 上的窗口?目前它是从一个小窗口开始的,我不希望用户必须不断地最大化它。
谢谢,
我想使用我的 MAUI 应用程序在其运行的平台上启动单独的后台服务。当 MAUI 应用程序本身未运行时,此后台服务利用 gRPC 从服务器接收数据。我知道它高度依赖于平台,因此为了便于讨论,我们假设我们只在 Windows 上执行此操作。
我的策略是将后台服务 .exe 与用于在计算机上安装应用程序的 .MSIX 一起包含,只需将 .exe 添加到 Platform/Windows 文件夹中,以便它与应用程序一起部署。但是,我无法使用 C# 找出该 .exe 文件在哪里。WPF 有一个“特殊”文件夹,可将我引导至任何系统上的 Program Files 文件夹,然后 C# 会将该 .exe 作为 Windows 服务启动。我找不到 MAUI 的等效项,因为 MAUI 的 FileSystem 类不允许这样做。
也许我的策略不正确。如果不是这个,那么使用 MAUI 应用程序部署后台服务的好策略是什么?
谢谢!
我试图隐藏桌面上图像中显示的后退按钮,但无论我尝试什么,它都会继续显示。
我努力了
<Shell.BackButtonBehavior>
<BackButtonBehavior IsVisible="False" IsEnabled="False" />
</Shell.BackButtonBehavior>
Run Code Online (Sandbox Code Playgroud)
我已经尝试遵循这篇文章为什么后退按钮隐藏在毛伊岛?
我的导航是这样完成的await Shell.Current.GoToAsync(new ShellNavigationState(location), false);
我错过了什么吗?
我正在使用 .NET MAUI 创建桌面应用程序。
在这里,我有一个ContentPage
标题为My title 的标题。
<ContentPage
x:Class="MAUI.Desktop.Pages.PlanningPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="My title">
....
Run Code Online (Sandbox Code Playgroud)
它的标题默认左对齐,你知道如何将其对齐到页面中心吗?如果可以的话,我也想给它添加更多的风格。
编辑:建议的解决方案
NavigationPage
。所以,这是我的解决方案:<ContentPage
x:Class="MAUI.Desktop.Pages.PlanningPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
>
<NavigationPage.TitleView>
<Label
x:Name="pageTitleView"
HorizontalTextAlignment="Center"
Text="My title"/>
</NavigationPage.TitleView>
......
Run Code Online (Sandbox Code Playgroud)
在代码隐藏xaml.cs
文件中:
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
pageTitleView.WidthRequest = width;
}
Run Code Online (Sandbox Code Playgroud)
Shell app
,您可以遵循@mm8 的答案我正在尝试导航到“TestView”页面,该页面位于我的 VisualStudio 解决方案的“Views”文件夹中。这里编译错误。
错误 XFC0000 无法解析类型“:TestView”
AppShell.xaml 文件
<FlyoutItem Title="test" FlyoutIcon="List">
<ShellContent
Title="Test Page"
ContentTemplate="{DataTemplate local:TestView}"
Route="TestView" />
</FlyoutItem>
Run Code Online (Sandbox Code Playgroud)
需要帮助解决编译错误