[英]Binding to nested Interfaces in xaml uwp
我有一個繼承自另一個接口的接口。 在我的代碼中,一切正常,從兩個界面都可以看到一切。 我試圖將接口綁定到xaml(因為我將其注入到ViewModel中),但是xaml僅從頂部接口看到屬性,而不從其繼承的接口看到屬性。
這是我正在做的一個簡單示例(請記住,這只是一個測試,以證明我遇到的問題):
public interface IA
{
void MethodA();
private string _bindingPropA;
public string BindingPropA
{
get { return _bindingPropA; }
set { Set(ref _bindingPropA, value); }
}
}
public interface IB : IA
{
void MethodB();
private string _bindingPropB;
public string BindingPropB
{
get { return _bindingPropB; }
set { Set(ref _bindingPropB, value); }
}
}
public class TestService1 : IB
{
public void MethodA()
{
Console.WriteLine("Method A");
}
public void MethodB()
{
Console.WriteLine("Method B");
}
}
public class DPTest1
{
public IB Injection;
public DPTest1(IB injection)
{
Injection = injection;
}
}
並實際測試
DPTest1 TestInjection1 = new DPTest1(new TestService1());
//Can see methods from both interfaces just fine
TestInjection1.Injection.MethodA();
TestInjection1.Injection.MethodB();
//but if i bind it to xaml it only sees the properties in interface "IB"!
如果我嘗試在xaml中綁定或x:Bind,我只能在“接口IB”中看到“方法B”
xaml不能綁定到嵌套接口是真的嗎,我必須將TestService編碼到我的類中,而不是將其注入接口中?
抱歉,錯誤警報...我要做的就是清理並重建,並且Xaml編輯器開始看到所有繼承的接口。 現在一切正常!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.