简体   繁体   English

如何将 Uno 平台与 Windows 社区工具包一起使用

[英]How to use Uno Platform with Windows Community Toolkit

I tried to make a demo application with this Uno Platform template.我试图用这个Uno Platform 模板制作一个演示应用程序。
All I wanted to do is add winui2 with this example and add the Windows Community Toolkit with this example .我想要做的就是在这个例子中添加 winui2 并在这个 例子中添加 Windows 社区工具包。

When doing the things mentioned in the tutorial for the Windows Community Toolkit, which is to install the following Nuget package:在做Windows社区工具包教程中提到的事情时,即安装以下Nuget package:

  • Uno .Microsoft.Toolkit.Uwp.UI.Controls.DataGrid Uno .Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
    • For iOS, Android, Web (WebAssembly)对于 iOS、Android、Web(WebAssembly) 对于安卓:
  • Microsoft.Toolkit.Uwp.UI.Controls.DataGrid Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
    • For the UWP app对于 UWP 应用程序

and use the following reference in my XAML:并在我的 XAML 中使用以下参考:
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"

In the XAML-file I added the following code-snipped provided by the tutorial:在 XAML 文件中,我添加了教程提供的以下代码片段:

<controls:DataGrid x:Name="dataGrid">
    <controls:DataGrid.Columns>
        <controls:DataGridTextColumn Header="Rank"/>
        <controls:DataGridComboBoxColumn Header="Mountain"/>
    </controls:DataGrid.Columns>
</controls:DataGrid>

Leading me to the following XAML-file in my Shell.xaml:将我带到我的 Shell.xaml 中的以下 XAML 文件:

<ContentControl
    x:Class="AndroidTest.Views.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AndroidTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:prismMvvm="using:Prism.Mvvm"
    xmlns:prismRegions="using:Prism.Regions"

    xmlns:winui="using:Microsoft.UI.Xaml.Controls"
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"

    prismMvvm:ViewModelLocator.AutowireViewModel="True"
    mc:Ignorable="d">


    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Margin="20">
            <TextBlock Text="{Binding Title}" FontSize="30" />
            <TextBlock Text="Welcome to Uno/WinUI and Prism!" FontSize="15" />

            <!-- winui -->
            <winui:NumberBox />
            <!-- community toolkit -->
            <controls:DataGrid x:Name="dataGrid">
                <controls:DataGrid.Columns>
                    <controls:DataGridTextColumn Header="Rank"/>
                    <controls:DataGridComboBoxColumn Header="Mountain"/>
                </controls:DataGrid.Columns>
            </controls:DataGrid>

        </StackPanel>
        <ContentControl Grid.Row="1" prismRegions:RegionManager.RegionName="ContentRegion" />
    </Grid>
</ContentControl>

Now the code works fine for UWP, but it does not work with Android anymore.现在该代码适用于 UWP,但它不再适用于 Android。 I get this error message in App.xaml.cs :我在App.xaml.cs中收到此错误消息:

Prism.Ioc.ContainerResolutionException: 'An unexpected error occurred while resolving 'AndroidTest.Views.Shell''

At the function:在 function:

protected override UIElement CreateShell()
{
    return Container.Resolve<Shell>();
}

And the following output:以及以下 output:

Loaded assembly: /data/user/0/AndroidTest.AndroidTest/files/.__override__/System.ComponentModel.DataAnnotations.dll [External]
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.TextBlock] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.TextBox] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.Control] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.FrameworkElement] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.Border] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.ScrollViewer] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[est.AndroidTes] Accessing hidden method Landroid/view/View;->initializeScrollbars(Landroid/content/res/TypedArray;)V (greylist, JNI, allowed)
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.Grid] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.Button] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[est.AndroidTes] Explicit concurrent copying GC freed 90(37KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 2487KB/3316KB, paused 289us total 3.144ms
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.ContentPresenter] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Windows.UI.Xaml.Controls.Primitives.RepeatButton] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[0:] The Bindable attribute is missing and the type [Microsoft.UI.Xaml.Controls.NumberBox] is not known by the MetadataProvider. Reflection was used instead of the binding engine and generated static metadata. Add the Bindable attribute to prevent this message and performance issues.
[monodroid-assembly] open_from_bundles: failed to load assembly en-US/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid.resources.dll
[monodroid-assembly] open_from_bundles: failed to load assembly en/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid.resources.dll
**Prism.Ioc.ContainerResolutionException:** 'An unexpected error occurred while resolving 'AndroidTest.Views.Shell''

Any ideas of what I am missing?关于我所缺少的任何想法?

Your issue is likely to be a linker issue.您的问题很可能是 linker 问题。 You can take a look at the documentation from Microsoft .您可以查看Microsoft 的文档

It turned out to be a problem with different versions of NuGet packages and problems with their dependencies.原来是不同版本的 NuGet 包和它们的依赖关系有问题。
For a functioning app with Uno Platform, Prism Library and the Windows Community Toolkit you need the following versions:对于具有 Uno 平台、Prism 库和 Windows 社区工具包的功能应用程序,您需要以下版本:

When installing these NuGet packages versions all dependencies are correct and it works fine.安装这些 NuGet 软件包版本时,所有依赖项都是正确的并且工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Uno Platform WASM 中使用.Net DLL? - How to use .Net DLL in Uno Platform WASM? 为 Windows 社区工具包安装了 Nuget - 尝试使用 TabView,构建错误 - Installed Nuget for Windows Community Toolkit - tried to use TabView, build error 无法使用 Windows 社区工具包中的 GridView 控件 - Unable to use GridView Control from Windows Community Toolkit 如何在UWP中设置DataGrid(Windows Community Toolkit) ItemSource? - How to set DataGrid(Windows Community Toolkit) ItemSource in UWP? 将 DispatcherHelper 从 MVVMLight 迁移到 Windows Community Toolkit - Migrating DispatcherHelper from MVVMLight to Windows Community Toolkit 如何在 Windows 运行时使用多语言应用工具包? - How to use multilingual app toolkit in Windows Runtime? 如何在 UNO 平台应用程序中使用 Microsoft.Extensions.DependencyInjection - How can I use Microsoft.Extensions.DependencyInjection in an UNO Platform app 如何在C#代码后面使用Xamarin Community Toolkit扩展属性和属性? - How to use Xamarin Community Toolkit extension properties and attributes in the C# code behind? 由于 Microsoft.Toolkit.Uwp.UI.dll 上的错误,Uno 平台中的 WebAssembly 无法编译 - WebAssembly in Uno platform not compiling due to an error on Microsoft.Toolkit.Uwp.UI.dll 使用 windows-community-toolkit 的 Print Helper 扩展分页 - Page break using Print Helper extension of windows-community-toolkit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM