简体   繁体   中英

Binding to nested Interfaces in xaml uwp

I have an Interface that inherits from another interface. In my code everything works fine, I can see everything from both interfaces. I am trying to Bind the Interface to xaml (because I'm injecting it into my ViewModel) but xaml only sees the properties from the top Interface and not the Interface it is inheriting from.

Here is a quick example of what I'm doing (keep in mind this is only a test to demonstrate the problem I'm having):

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;
    }
}

And actually testing it

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"!

If I try to Bind or x:Bind it in xaml I can only see "Method B" in "Interface IB"

Is it true that xaml can't bind to nested interfaces and I'll have to code the TestService into my class instead of injecting it into an interface???

Sorry, False alarm... All I had to do is clean and rebuild and the Xaml editor started seeing all the inherited Interfaces. It's all working find now!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM