【发布时间】:2021-04-15 19:29:10
【问题描述】:
我目前正在使用 Prism 试用 Uno Platform,看看是否值得将我的项目从 WPF 迁移到 UWP 和 Uno。我已经使用 Prism 模板构建了这个应用程序。
我目前遇到了一个问题,我通常通过存储在静态区域名称类中的静态调用区域名称来将区域分配给 ContentControl。
我的 WPF XAML 代码,来自 Shell.xaml:
<ContentControl Grid.Row="0"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="0,0,0,11"
prismRegions:RegionManager.RegionName="{x:Static blankCore:RegionNames.ContentHeaderRegion}"/>
但是,这不起作用,因为 x:Static 在 UWP 中不存在(XML 命名空间中的未知类型“静态”)。因此,在查看了一些关于 UWP 的文档后,我使用了 x:Bind,现在代码如下所示:
<ContentControl Grid.Row="0"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
Margin="0,0,0,11"
prismRegions:RegionManager.RegionName="{x:Bind blankCore:RegionNames.ContentHeaderRegion}"/>
这是为 UWP 编译和运行的,但在切换到 WASM 或 Android 时,生成的文件中出现各种错误:
c32.SetBinding(global::Prism.Regions.RegionManager.RegionNameProperty, new Windows.UI.Xaml.Data.Binding{ Mode = BindingMode.OneTime }.Apply(___b => /*defaultBindModeOneTime*/ global::Uno.UI.Xaml.BindingHelper.SetBindingXBindProvider(___b, this, ___ctx => ___ctx is global::BlankApp1.Shared.Views.Shell ___tctx ? (object)(___tctx.global::BlankApp1.Core.RegionNames.AuthenticateRegion) : null, null )));
我目前的RegionNames静态类如下:
namespace BlankApp1.Core
{
public class RegionNames
{
public static string ContentHeaderRegion = "ContentHeaderRegion";
/// ...
}
}
使用 'x:Bind' 的方法是否正确,是否有解决方法? 还是我应该做点别的?
【问题讨论】:
-
这通常发生在工具由于某种原因无法解析目标类型时。包含
RegionNames的文件是否在 Wasm/android 和其他项目头中直接或间接引用? -
我已经检查过了,BlankApp1.Droid 和 BlankApp1.WASM 项目也引用了在它们和 BlankApp1.UWP 之间共享的 BlankApp1.Core 类库。 RegionNames.cs 位于 BlankApp1.Core 项目中。
-
这很奇怪。你能用你的空白应用在 Uno 存储库上打开一个问题吗?这将有助于排除故障。谢谢!
标签: wpf xaml uwp webassembly uno-platform