Resolving interface as UIElement (Unity, PRISM, C #)

when using PRISM, the normal way to connect to a unit is to define an interface and register an implementation with that interface. Now I have a problem with views. The scenario is simple:

Let's say a custom video control that lets you set a play command. This control is defined by a simple "IPlayControlView" interface. The obvious problem is when I resolve this control and try to add it in StackPanel

, it doesn't work because I have it IPlayControl

, not UIElement

.

I can pass it UIElement

on because I know what it is UIElement

. But is there a better way, something like

public interface IPlayControlView : UIElement

      

It won't work, but maybe something else will do the trick ...

This is kind of a general question, if I resolve views using interfaces, I will run into this problem every time. It may not be the way it's done, but I've always thought of one of ... Okay, just got it. I'll just extend the IPlayControl with one UIElement property and set it as a reference to myself. So, never mind, the question was asked :-)

If there is a better way, I always enjoy learning new things. Perhaps an IUIElement?

Chris

+2


source to share


1 answer


The way you describe in your penultimate paragraph is how I do it. For example, if I want to use mine IShell

like UIElement

(which is pretty normal), I declare an interface something like this:

public interface IShell
{
    UIElement GetView();
}

      



Then in my implementation:

public partial class MyMainShell : UserControl, IShell
{
    public UIElement GetView()
    {
        return this;
    }
}

      

+6


source







All Articles