如何通过 Windows Community Toolkit 使用 Uno Platform
How to use Uno Platform with Windows Community Toolkit
我尝试使用 this Uno Platform 模板制作演示应用程序。
我想要做的就是添加带有 this example and add the Windows Community Toolkit with this example.
的 winui2
在做 Windows Community Toolkit 教程中提到的事情时,即安装以下 Nuget 包:
- 乌诺.Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
- 对于iOS、Android、网络(WebAssembly)
- Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
- 对于 UWP 应用
并在我的 XAML 中使用以下参考:
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
在 XAML 文件中,我添加了教程提供的以下代码片段:
<controls:DataGrid x:Name="dataGrid">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="Rank"/>
<controls:DataGridComboBoxColumn Header="Mountain"/>
</controls:DataGrid.Columns>
</controls:DataGrid>
将我带到 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>
现在代码适用于 UWP,但它不再适用于 Android。我在 App.xaml.cs
:
中收到此错误消息
Prism.Ioc.ContainerResolutionException: 'An unexpected error occurred while resolving 'AndroidTest.Views.Shell''
在函数中:
protected override UIElement CreateShell()
{
return Container.Resolve<Shell>();
}
以及以下输出:
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''
知道我遗漏了什么吗?
您的问题很可能是链接器问题。你可以看看documentation from Microsoft.
原来是不同版本的NuGet包的问题及其依赖的问题
要使用 Uno Platform、Prism Library 和 Windows Community Toolkit 运行应用程序,您需要以下版本:
- Uno 模板Version 3.7.4
- Uno.Microsoft.Toolkit.Uwp.UI.Controls.DataGrid Version 7.0.0.
安装这些 NuGet 包版本时,所有依赖项都是正确的,并且工作正常。
我尝试使用 this Uno Platform 模板制作演示应用程序。
我想要做的就是添加带有 this example and add the Windows Community Toolkit with this example.
在做 Windows Community Toolkit 教程中提到的事情时,即安装以下 Nuget 包:
- 乌诺.Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
- 对于iOS、Android、网络(WebAssembly)
- 对于iOS、Android、网络(WebAssembly)
- Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
- 对于 UWP 应用
并在我的 XAML 中使用以下参考:
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
在 XAML 文件中,我添加了教程提供的以下代码片段:
<controls:DataGrid x:Name="dataGrid">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="Rank"/>
<controls:DataGridComboBoxColumn Header="Mountain"/>
</controls:DataGrid.Columns>
</controls:DataGrid>
将我带到 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>
现在代码适用于 UWP,但它不再适用于 Android。我在 App.xaml.cs
:
Prism.Ioc.ContainerResolutionException: 'An unexpected error occurred while resolving 'AndroidTest.Views.Shell''
在函数中:
protected override UIElement CreateShell()
{
return Container.Resolve<Shell>();
}
以及以下输出:
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''
知道我遗漏了什么吗?
您的问题很可能是链接器问题。你可以看看documentation from Microsoft.
原来是不同版本的NuGet包的问题及其依赖的问题
要使用 Uno Platform、Prism Library 和 Windows Community Toolkit 运行应用程序,您需要以下版本:
- Uno 模板Version 3.7.4
- Uno.Microsoft.Toolkit.Uwp.UI.Controls.DataGrid Version 7.0.0.
安装这些 NuGet 包版本时,所有依赖项都是正确的,并且工作正常。