我创建了一个毛伊岛 Windows 应用程序。我希望通过 URI 激活应用程序并将查询参数传递给应用程序。
我在包清单中添加了用于通过 uri 调用应用程序的 Windows 协议:
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="my-app">
<uap:DisplayName>My App</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
</Extensions>
Run Code Online (Sandbox Code Playgroud)
当我通过浏览器 my-app://foo.com?user=123456 激活应用程序时,应用程序启动,但它作为冷启动启动。在我的 Win UI 应用程序中,我覆盖了 onLaunched 方法,但无论我如何启动该应用程序,我都无法访问该协议。我正在尝试从我的 UWP 应用程序重新创建以下代码:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
var queryStr = eventArgs.Uri.Query;
App.UserId = System.Web.HttpUtility.ParseQueryString(queryStr).Get("user");
// Navigate to a view
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
Xamarin.Forms.Forms.Init(args);
Window.Current.Content = rootFrame;
}
rootFrame.Navigate(typeof(MainPage), …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项目是更好的选择
如何使用绑定和 DataTemplate 呈现字符串、数字或视图模型?
我正在寻找 WPF ContentControl 的 MAUI 替代品。
具有ContentViewContent 属性,但这是来自 type View。具有ContentPresenterContent 属性,但这也来自 type View。<Ignorable>WTF,为什么它只能呈现一个视图,而不被命名为 ViewPresenter ???有时 MAUI 很奇怪。</Ignorable>
如何通过为每种数据类型定义数据模板来呈现任何内容?
class PropertyViewModel {
public string Name {get;set;}
public object Value {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
<Page.Resources>
<DataTemplate DataType="System.String">
<Entry Text="{Binding}/>
</DataTemplate>
<DataTemplate DataType="System.Int32">
<NumberPicker Value="{Binding}/>
</DataTemplate>
.. more templates, eg. DatePicker for System.DateOnly
</Page.Resources>
<DockLayout>
<Label Text="{Binding Name}
<TemplatedContenView Content={Binding Value}/>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
TemplatedContenView 或 ContentControl(MAUI 中不存在)可以对不同类型的值使用不同的模板。在 WPF 中,ContentControl 使用 ContentTemplate、ContentTemplateSelector,或者如果未指定,则它会查找资源来查找模板。
<Ignorable>对于 MAUI,我经常有一种感觉,我必须不断地重新发明 …
我在使用 MAUI 的 RC1 时遇到问题,导致我从 Android 清单中删除了这部分:
<application
...
android:icon="@mipmap/appicon"
android:roundIcon="@mipmap/appicon_round"
...>
</application>
Run Code Online (Sandbox Code Playgroud)
现在它已经 GA 了,我正在尝试将其添加回来,因为在 Android 中我的应用程序图标没有显示 - 相反,它只是通用的 Android 图标。当我将其添加回我的 Android 清单时,如下所示:
<application android:allowBackup="true"
android:supportsRtl="true"
android:icon="@mipmap/appicon"
android:roundIcon="@mipmap/appicon_round">
</application>
Run Code Online (Sandbox Code Playgroud)
我遇到编译错误,我不知道如何解决。注意:我确实有一个名为“appicon.png”的文件,并且它确实可以作为 iOS 上的应用程序图标正常工作。错误看起来像这样:
APT2260 resource xml/microsoft_maui_essentials_fileprovider_file_paths (aka com.watchlikes.watchlikesapp:xml/microsoft_maui_essentials_fileprovider_file_paths) not found.
APT2260 resource style/Maui.SplashTheme (aka com.watchlikes.watchlikesapp:style/Maui.SplashTheme) not found.
APT2067 failed processing manifest.
Run Code Online (Sandbox Code Playgroud)
如果我从清单文件中取出 android:icon 和 android:roundIcon 属性,它会再次正确编译。知道这个问题是什么,和/或如何解决它吗?
当我尝试在发布模式下运行程序时,出现以下错误:
Severity Code Description Project File Line Suppression State
Error XAGJS7004 System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState)
at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache)
at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 MauiApp1 C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.440\tools\Xamarin.Android.Common.targets 1438
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为在调试模式下它工作正常,但我在网上找不到任何答案。 窗口片段
我正在尝试在 MAUI 中(使用 .NET 6)为 Android 应用程序创建一个前台服务,但目前没有关于实现此目的的教程(我可以找到)。
添加前台服务的最佳起点是什么,或者如何创建它?
我有各种实现来partial class DeviceServices为 Android、iOS 等提供某些设备或操作系统特定功能的平台特定实现。我的应用程序的目标 API 级别为 33.0,最低版本为 API 级别 21.0。
某些 API 特定于某些 Android 版本及更高版本,因此我想确保仅在受支持的版本上调用它们。但是,我总是收到以下警告(以及类似的警告,具体取决于所使用的 API):
警告 CA1416:可在“Android”21.0 及更高版本上访问此调用站点。“WindowInsets.Type.SystemBars()”仅支持:“android”30.0 及更高版本。
以下隐藏和显示系统栏的代码适用于我迄今为止尝试过的所有设备和模拟器,但我担心早期的 Android 版本。尽管检查了正确的目标 API 版本,我仍然收到上面的警告:
static partial class DeviceServices
{
private static Activity _activity;
public static void SetActivity(Activity activity)
{
_activity = activity;
}
public static partial void HideSystemControls()
{
#if ANDROID30_0_OR_GREATER
if (Build.VERSION.SdkInt >= BuildVersionCodes.R) //R == API level 30.0
{
_activity?.Window?.InsetsController?.Hide(WindowInsets.Type.SystemBars());
}
#endif
}
public static partial void ShowSystemControls()
{
#if ANDROID30_0_OR_GREATER
if (Build.VERSION.SdkInt >= …Run Code Online (Sandbox Code Playgroud) 我读到,我们可以在 MAUI 项目中使用特定于平台的 C#,但我需要使用特定于平台的 XAML 文件。在文档中找不到任何内容。
背景: 在 Android 上,当从绑定的 ObservableCollection 中删除项目时,ListView 内的 SwipeView 会引发 Java 错误(“指定的子项已经有父项。您必须首先在子项的父项上调用removeView()。”),因此我使用CollectionView 在这里(没有错误)。在 iOS 上,当与页面上的其他元素一起使用时,CollectionView 确实会延伸到页面下端之外(看起来,在 iOS 上 CollectionView 确实想要占据整个屏幕高度),所以我必须在这里使用 ListView。但在 iOS 上,不会发生上述错误。
昨天,我跟随我的同事从 .NET 7.0 更新到 .NET 8.0,并使其立即运行。然而,对于我自己来说,在我的 VS Mac 和我的 VS Windows 上我都收到错误
错误 NETSDK1139:无法识别目标平台标识符 ios。
(如果设置为 ios 作为部署目标,此错误也会出现在 android 版本中)
目标框架列为 net8.0-android;net8.0-ios;
以下这些我都有了~
还有一点值得注意的是~
我真的很感谢任何人在这个主题上的知识,特别是任何以前遇到过并处理过这个问题的人。
我创建了一个名为TestMauiApp的新 MAUI .NET 8.0 项目(与 Visual Studio 2022 创建的默认值相比没有任何更改) 。然后,我将一个 MAUI 类库添加到名为MauiLibrary的解决方案中,并将该类库链接到我的项目中。当我在 Azure Pipeline 上构建它时,出现以下错误:
"/Users/runner/work/1/s/TestMauiApp/TestMauiApp.sln" (SignAndroidPackage target) (1) ->
"/Users/runner/work/1/s/TestMauiApp/SkiaGum.Mobile/MauiLibrary.csproj" (SignAndroidPackage target) (3) ->
(_BuildApkEmbed target) ->
/Users/runner/hostedtoolcache/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.43/tools/Xamarin.Android.Common.targets(2150,3): error XABBA7009: System.InvalidOperationException: Assembly compression info not found for key '__CompressedAssembliesInfo:/Users/runner/work/1/s/TestMauiApp/SkiaGum.Mobile/MauiLibrary.csproj'. Compression will not be performed. [/Users/runner/work/1/s/TestMauiApp/SkiaGum.Mobile/MauiLibrary.csproj::TargetFramework=net8.0-android]
/Users/runner/hostedtoolcache/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.43/tools/Xamarin.Android.Common.targets(2150,3): error XABBA7009: at Xamarin.Android.Tasks.BuildApk.RunTask() [/Users/runner/work/1/s/TestMauiApp/SkiaGum.Mobile/MauiLibrary.csproj::TargetFramework=net8.0-android]
/Users/runner/hostedtoolcache/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.43/tools/Xamarin.Android.Common.targets(2150,3): error XABBA7009: at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [/Users/runner/work/1/s/TestMauiApp/SkiaGum.Mobile/MauiLibrary.csproj::TargetFramework=net8.0-android]
Run Code Online (Sandbox Code Playgroud)
我无法在任何地方找到有关此问题的信息,因此我不确定从哪里开始解决此问题。
通过将以下行添加到我的MauiLibrary csproj 文件中,我能够克服此错误(或者可能只是将其替换为其他错误)。
<AndroidEnableAssemblyCompression>false</AndroidEnableAssemblyCompression>
Run Code Online (Sandbox Code Playgroud)
通过这样做,我现在得到一个不同的错误:
"/Users/runner/work/1/s/TestMauiApp/TestMauiApp.sln" (SignAndroidPackage target) (1) ->
"/Users/runner/work/1/s/TestMauiApp/SkiaGum.Mobile/MauiLibrary.csproj" (SignAndroidPackage target) …Run Code Online (Sandbox Code Playgroud) maui ×10
android ×5
c# ×4
.net ×2
.net-maui ×2
winui-3 ×2
azure-devops ×1
maui-windows ×1
xaml ×1
xml ×1