标签: maui-windows

MAUI .NET 设置窗口大小

如何在 MAUI 中设置窗口大小?

背景信息:我只关心此应用程序的 Windows - 我选择了 MAUI,因此我可以将 Blazor 用于桌面应用程序。由于某种原因,默认窗口尺寸很大(几乎占据了我所有的 1440p 屏幕空间)。我正在制作的应用程序只需要大约 600x600。尽管我很高兴让应用程序能够响应,但有一种方法可以固定窗口大小也会很有帮助。

maui maui-blazor maui-windows

30
推荐指数
4
解决办法
3万
查看次数

.NET MAUI 错误没有为此对象定义无参数构造函数

将我的视图绑定到视图模型时发生。

错误描述:

System.MissingMethodException: 'No parameterless constructor defined for type 'yournamespace.view.pagename'.'
Run Code Online (Sandbox Code Playgroud)

c# maui .net-maui maui-community-toolkit maui-windows

11
推荐指数
1
解决办法
6315
查看次数

我可以在 MAUI 项目中使用现有的 WinUI3 控件吗?

是否可以在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项目是更好的选择

winui-3 maui .net-maui maui-windows

7
推荐指数
1
解决办法
2213
查看次数

.net MAUI 如何在启动时最大化应用程序

如何使 .net MAUI 应用程序在启动时最大化 Windows 上的窗口?目前它是从一个小窗口开始的,我不希望用户必须不断地最大化它。

谢谢,

.net maui maui-windows

5
推荐指数
2
解决办法
3866
查看次数

从 MAUI 应用程序运行/启动单独的后台服务

我想使用我的 MAUI 应用程序在其运行的平台上启动单独的后台服务。当 MAUI 应用程序本身未运行时,此后台服务利用 gRPC 从服务器接收数据。我知道它高度依赖于平台,因此为了便于讨论,我们假设我们只在 Windows 上执行此操作。

我的策略是将后台服务 .exe 与用于在计算机上安装应用程序的 .MSIX 一起包含,只需将 .exe 添加到 Platform/Windows 文件夹中,以便它与应用程序一起部署。但是,我无法使用 C# 找出该 .exe 文件在哪里。WPF 有一个“特殊”文件夹,可将我引导至任何系统上的 Program Files 文件夹,然后 C# 会将该 .exe 作为 Windows 服务启动。我找不到 MAUI 的等效项,因为 MAUI 的 FileSystem 类不允许这样做。

也许我的策略不正确。如果不是这个,那么使用 MAUI 应用程序部署后台服务的好策略是什么?

谢谢!

.net c# grpc maui maui-windows

5
推荐指数
1
解决办法
2410
查看次数

dotnet maui 如何隐藏桌面上的后退按钮?

我试图隐藏桌面上图像中显示的后退按钮,但无论我尝试什么,它都会继续显示。

我努力了

<Shell.BackButtonBehavior>
    <BackButtonBehavior IsVisible="False" IsEnabled="False" />
</Shell.BackButtonBehavior>
Run Code Online (Sandbox Code Playgroud)

我已经尝试遵循这篇文章为什么后退按钮隐藏在毛伊岛?

我的导航是这样完成的await Shell.Current.GoToAsync(new ShellNavigationState(location), false);

我错过了什么吗?

在此输入图像描述

maui .net-maui maui-windows

4
推荐指数
1
解决办法
9694
查看次数

如何在.Net MAUI 中为 ContentPage 标题添加样式?

我正在使用 .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)

.net winui-3 maui maui-windows

3
推荐指数
1
解决办法
4914
查看次数

.Net Maui - ShellContent 导航问题

我正在尝试导航到“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)

需要帮助解决编译错误

这里是我的 GitHub 项目MPC-Calculator Maui Branch的链接

在此输入图像描述

maui maui-windows .net-maui.shell

2
推荐指数
1
解决办法
1116
查看次数