标签: maui

为什么 .NET-Maui 全局样式不起作用?

我已在 .Net Maui 中声明了全局样式并尝试从其中一个页面访问它,但它抛出异常

Microsoft.Maui.Controls.Xaml.XamlParseException:位置 10:37。类型转换器失败:调用目标已引发异常。Microsoft.Maui.Controls.Xaml.XamlParseException:位置 8:34。未找到主键的 StaticResource。

应用程序.xaml代码

<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:MyApp"
         x:Class="MyApp.App">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
            <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    <Style x:Key="redLabelStyle"
           TargetType="Label">
        <Setter Property="TextColor"
                    Value="Red"/>
        <Setter Property="FontSize"
                    Value="Small"/>
        <Setter Property="FontAttributes"
                    Value="Bold"/>
    </Style>

    <Style TargetType="Label">
        <Setter Property="TextColor"
                    Value="Green"/>
        <Setter Property="FontSize"
                    Value="Small"/>
        <Setter Property="FontAttributes"
                    Value="Bold"/>
    </Style>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

MainPage.xaml代码

<?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"
         NavigationPage.HasNavigationBar="False"
         x:Class="MyApp.MainPage">

<VerticalStackLayout HorizontalOptions="CenterAndExpand"
                     VerticalOptions="CenterAndExpand">
    <Label Style="{StaticResource redLabelStyle}"
           Text="Global Style Red Label"/>
    <Label …
Run Code Online (Sandbox Code Playgroud)

xamarin xamarin.forms maui .net-maui

6
推荐指数
1
解决办法
4948
查看次数

将 .NET MAUI 部署到 IOS 模拟器错误:simctl 返回退出代码 22

问题

我在使用 .NET Maui 部署到任何 iOS 模拟器时遇到问题。我收到以下错误:无法在设备“iOS 15.5 - iPhone 11”上安装应用程序“com.app.name”,simctl 返回退出代码 22。

错误信息

Mac 构建服务器上的控制台报告“应用程序 Info.plist 不包含有效的 CFBundleVersion”。

信息。Mac 上部署文件夹中的列表显示以下内容: 捆绑包版本 = 1 捆绑包版本字符串(短)= 2.0

信息。列表

我尝试过的

我已经在 Visual Studio 中使用多个值和设置修改了版本和构建,但没有效果。我已使用“重置内容和设置”重置了模拟器。

其他注意事项

我可以使用相同的版本和构建设置,使用新的 .NET Maui 项目部署到同一个模拟器。尽管它只是加载启动画面然后黑屏,但它确实部署了。

这在某个时候是有效的,我不确定它具体是什么时候坏掉的。

我相信问题出在我的项目上,我只是不确定下一步该去哪里。任何关于下一步该去哪里的帮助将不胜感激。

[更新] Xamarin 与毛伊岛

22 年 10 月 12 日更新 - 我将当前的生产版本(使用 Xamarin Forms)与使用相同版本号的 Maui 版本进行了比较。Xamarin Forms 项目在 iOS 模拟器中运行。除了毛伊岛特有的内容之外,Info.plist 文件是相同的。

plist比较

maui

6
推荐指数
1
解决办法
1509
查看次数

Package.appxmanifest 中的 $placeholder$ 标签代表什么?

我尝试将起始示例 .NET MAUI Blazor 混合应用程序重构为 Razor 类库(数据、页面、wwwroot 和共享文件夹),.NET MAUI Blazor 代码库的其余部分将其作为单独的项目引用。我已更新 _Imports.Razor 中的 MAUI 使用以引用 RCL。我收到编译错误,但是找不到 Package.appxmanifest 中 $placeholder$.png 的启动图像。

我想知道 appxmanifest 中的 $placeholder$ 到底指的是什么?是否有任何特定的文件夹或位置?

maui maui-blazor

6
推荐指数
0
解决办法
505
查看次数

.NET MAUI 导航动画

如果我想在 MAUI 中为从一个页面到另一页面的过渡设置动画,我需要使用true值激活它:

await Shell.Current.GoToAsync($"//{nameof(DashboardPage)}", true);
Run Code Online (Sandbox Code Playgroud)

这会动画化页面从右到左的过渡。有没有办法反转转换 => 从左到右?有什么建议么?我在 MAUI 文档中没有看到这个选项。有什么窍门吗?

.net navigation animation maui

6
推荐指数
1
解决办法
4872
查看次数

未找到密钥的 .NET MAUI StaticResource

当我将主页注入到 App 类构造函数时,我得到StaticResource not find for key 但如果我不在 App 构造函数中注入主页,它就会起作用。

我有一个全局资源主题文件,我在App.xaml.cs上调用该文件,在其中声明静态资源:

 <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
            <ResourceDictionary Source="Themes/LightTheme.xaml" /> <!--Theme file-->
            <ResourceDictionary Source="Themes/DarkTheme.xaml" /> <!--Theme file-->
            <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

这是我的 App.cs 文件:

public App(MainPage mainPage)
{

    InitializeComponent();

    MainPage = mainPage;

}
Run Code Online (Sandbox Code Playgroud)

以下代码位于 MainPage.xaml 中:

    <StackLayout BackgroundColor="{StaticResource SecondaryBackroundColor}" Grid.Row="0">
        <Image 
            Source="ic_logo.png"
            SemanticProperties.Description="Cute dot net bot waving hi to you!"
            HeightRequest="200"
            HorizontalOptions="Center"  VerticalOptions="CenterAndExpand"/>

    </StackLayout>
Run Code Online (Sandbox Code Playgroud)

我已将MainPage添加到 mauiprogram.cs 类中

builder.Services.AddTransient<MainPage>();

c# xaml dependency-injection maui

6
推荐指数
1
解决办法
4553
查看次数

.NET MAUI - Horizo​​ntalTextAlignment="Center" 不适用于 Android

我已将一个项目从 Xamarin 转换为 .Net MAUI。MAUI 有很多问题,但最烦人的问题之一是设置HorizontalTextAlignmentCenter在 Android 中不起作用。对于只有单行的标签,常规 Horizo​​ntalAlignment 有效,但对于多行标签,它不是一个有效的解决方案:

在此输入图像描述

在屏幕截图中,两个标题标签使用 VisualElement 上的 Horizo​​ntalAlignment 居中,但对于下面较长的文本,这不起作用。尽管标签元素居中,但内部文本并未居中对齐。

有没有人有办法解决吗?

PSHorizontalTextAlignment在 iOS 中工作,当我在热重载中操作它时,它也在我的 Android 模拟器中工作。

xaml text-alignment xamarin maui

6
推荐指数
1
解决办法
1412
查看次数

.Net MAUI Android 应用程序:在启动屏幕时更改导航和状态栏颜色

我正在尝试更改 .Net MAUI Android 应用程序中的导航栏和状态栏背景颜色。

我找到了当应用程序初始化加载时如何执行此操作(状态栏:使用 MauiCommunityToolkit StatusBarBehavior StatusBarColor 功能。导航栏:使用 Window.SetNavigationBarColor)。

但我还没有找到当应用程序启动并显示启动屏幕时如何执行此操作。我需要状态栏和导航栏的黑色背景颜色,但当应用程序启动时,导航栏为白色,状态栏为紫色(默认 .Net MAUI 颜色)。我附上了一张启动时的外观图像。

我尝试更改 Resources/colors.xml 中的主颜色,但没有成功。

我的应用程序是一个 MAUI 单一项目模板(Android 和 iOS)。

预先感谢您查看此问题。在此输入图像描述

更新:我能够仅更改状态栏,更改 Platforms/Android/Resources/colors.xml 中的默认 colorPrimaryDark 值 在此输入图像描述

但仍在研究如何更改导航栏颜色。 在此输入图像描述

.net android maui

6
推荐指数
1
解决办法
4650
查看次数

如何修复 .NET MAUI 中的 DEP0700 flashScreen

DEP0700: Registration of the app failed. [0x80073CF6] AppxManifest.xml(33,27): error 0x80070003: Cannot install or update package C2825F9A-1C95-43C1-96C9-3ABE72D02D1D_9zz4h110yvjzm because the splash screen image [splashSplashScreen.png] cannot be located. Verify that the package contains an image that can be used as a splash screen for the application, and that the package manifest points to the correct location in the package where this splash screen image can be found.
Run Code Online (Sandbox Code Playgroud)

如何修复 .NET MAUI 中的此错误?此错误表明splashSplashScreen.png 丢失。有时会在删除我的 bin 目录或 obj 目录后发生。

目前,我连续多次删除 bin 和 obj 文件夹,并多次重新生成项目,以便它再次工作。我想避免这个问题并知道它从何而来。

c# maui

6
推荐指数
1
解决办法
640
查看次数

CollectionView 项目未出现在发布模式下

z在 .net Maui 应用程序中,我遇到以下问题:我的集合视图在调试模式下工作正常,但在发布模式下,集合视图仅显示一个白色矩形,而不是图像和两个标签。onClick 函数工作正常:\n这是 xaml:

\n
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"\n             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"\n             xmlns:vm="clr-namespace:VegaMaui"\n             xmlns:model="clr-namespace:VegaMaui.Model"\n             x:Class="VegaMaui.MenuDetails"   x:DataType="vm:MenuDetailsViewModel"        \n             Title="\xd4\xb1\xd5\xba\xd6\x80\xd5\xa1\xd5\xb6\xd6\x84\xd5\xb6\xd5\xa5\xd6\x80"\n             BackgroundColor="#f9f9f9">   \n    <CollectionView \n            RemainingItemsThreshold="5"\n            RemainingItemsThresholdReachedCommand="{Binding LoadMoreS}"\n            SelectionMode="Single"\n            SelectionChanged="OnProdSelectionChanged"\n            ItemsSource="{Binding ProdListS}"\n            x:Name="prodcollect">\n        <CollectionView.ItemsLayout>\n            <GridItemsLayout Orientation="Vertical"\n                        Span="2" />\n        </CollectionView.ItemsLayout>       \n        <CollectionView.ItemTemplate>            \n            <DataTemplate x:DataType="model:ProductImg">                    \n                <Grid Margin="5,5,5,5" Padding="1" >\n                    <Grid.RowDefinitions>\n                        <RowDefinition Height="Auto" />\n                        <RowDefinition Height="Auto" />\n                        <RowDefinition Height="Auto" />\n                        <RowDefinition Height="Auto" />\n                    </Grid.RowDefinitions>\n                    <Grid.ColumnDefinitions>\n                        <ColumnDefinition Width="*" />                           \n                    </Grid.ColumnDefinitions>\n                    <Image\n                        Grid.Row="0"                           \n                        Grid.Column="0"                         \n                        Source= "{Binding firstPicture}"                        \n                        Aspect="AspectFill"/>                    \n                    <Label Grid.Row="1"\n                        Grid.Column="0"                      \n                        FontAttributes="Bold"\n …
Run Code Online (Sandbox Code Playgroud)

.net release image collectionview maui

6
推荐指数
1
解决办法
459
查看次数

Android 上的 MAUI 网格列宽度错误?

我正在使用 Grid.ColumnDefinition 但百分比似乎无法在 Android 上正常工作,而在 Windows 上却可以正常工作。

<ContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Maui.Views.TestMapPage"
             Title="TestMap">
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="3*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <BoxView Grid.Row="0" Grid.ColumnSpan="3" Color="Blue" />
        <BoxView Grid.Row="1" Grid.Column="0" Color="Purple" />
        <BoxView Grid.Row="1" Grid.Column="1" Color="Yellow" />
        <BoxView Grid.Row="1" Grid.Column="2" Color="Purple" />
        <BoxView Grid.Row="2" Grid.ColumnSpan="3" Color="Red" />
    </Grid>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

结果并不如预期(20%,60%,20%)

  1. 为什么?
  2. 知道如何解决这个问题吗?

截屏

编辑并回答问题:

  • 我正在 Pixel 3a XL - API 33 (Android 13.0) 上进行测试
  • 更改为 MainPage = …

.net maui

6
推荐指数
1
解决办法
507
查看次数