UWP XAML x:无法识别绑定的继承接口

Sim*_*tes 10 c# xaml uwp xbind

在UWP XAML应用程序中使用x:Bind时,请考虑以下事项:

interface IBaseInterface
{
    string A { get; set; }
}
interface ISubInterface : IBaseInterface
{
    string B { get; set; }
}
class ImplementationClass : ISubInterface
{
    public string A { get; set; }
    public string B { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在Page类中,我们有以下内容:

public partial class MainPage : Page
{
    public ISubClass TheObject = new ImplementationClass { A = "1", B = "2" };
    //All the rest goes here
}
Run Code Online (Sandbox Code Playgroud)

在MainPage XAML中,我们有以下代码段:

<TextBlock Text={x:Bind Path=TheObject.A}></TextBlock>
Run Code Online (Sandbox Code Playgroud)

这导致以下编译器错误:XamlCompiler错误WMC1110:无效的绑定路径'A':在'ISubInterface'类型上找不到属性'A'

但是,以下工作正常:

<TextBlock Text={x:Bind Path=TheObject.B}></TextBlock>
Run Code Online (Sandbox Code Playgroud)

有人知道UWP XAML平台的已知限制是否编译器无法识别继承的接口属性?或者这应该被视为一个错误?有没有已知的解决方法?

非常感谢帮助.提前致谢!

Amy*_*SFT 8

是的,在进行一些测试和研究之后,使用X:Bind时,编译器似乎无法识别继承的接口属性.

作为一种解决方法,我们可以使用传统的Binding而不是X:Bind,如下所示:

在.xaml中:

<Grid Name="MyRootGrid">
         <TextBlock Text="{Binding A}"></TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)

在xaml.cs中:

MyGrid.DataContext = TheObject;
Run Code Online (Sandbox Code Playgroud)