tags:

views:

319

answers:

1

Hi,

when using PRISM the normal way to hookup things with unity is to define an interface and register an implementation with this interface. Now, I have a problem regarding views. The scenario is simple:

Assume a custom video control which allows to set a Play command. This control is defined by a simple interface "IPlayControlView". The obvious problem, when I resolve this control and try to add it to a StackPanel, it does not work, because I have an IPlayControl, not an UIElement.

I can cast it to UIElement, because I know that it is an UIElement. But is there any better way, something like

public interface IPlayControlView : UIElement

This does not work, but maybe some other thing will do the trick...

It is kind of a general question, if I resolve views using interfaces I will run into this problem every time. Perhaps its not the way it is done, but I always thought one of the .... Ok, just got an idea. I will just extend the IPlayControl with one property UIElement and set this as reference to itself. So, nevermind, question answered while typing :-)

If there is a better way, I always like to learn new things. Perhaps a IUIElement?

Chris

+2  A: 

The way you describe in your penultimate paragraph is the way I do it. For example, if I want to use my IShell as an UIElement (which is pretty normal) I declare the interface something like:

public interface IShell
{
    UIElement GetView();
}

Then in my implementation:

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