将界面解析为 UIElement(Unity、PRISM、C#)
使用 PRISM 时,统一连接事物的正常方法是定义一个接口并使用该接口注册一个实现。现在,我有一个关于观点的问题。该场景很简单:
假设一个自定义视频控件允许设置播放命令。该控件由简单的接口“IPlayControlView”定义。明显的问题是,当我解决此控件并尝试将其添加到 StackPanel
时,它不起作用,因为我有一个 IPlayControl
,而不是 UIElement< /代码>。
我可以将其转换为 UIElement
,因为我知道它是一个 UIElement
。但是有没有更好的方法,比如
public interface IPlayControlView : UIElement
This 不起作用,但也许其他一些东西可以解决问题......
这是一个普遍的问题,如果我使用接口解析视图,我每次都会遇到这个问题。也许这不是它的做法,但我一直认为其中之一...... 好吧,刚刚有了一个主意。我将仅使用一个属性 UIElement 扩展 IPlayControl 并将其设置为对其自身的引用。所以,没关系,在打字时回答问题:-)
如果有更好的方法,我总是喜欢学习新东西。也许是 IUIElement?
克里斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你在倒数第二段中描述的方式就是我的做法。例如,如果我想使用我的
IShell
作为UIElement
(这很正常),我声明的接口如下:然后在我的实现中:
The way you describe in your penultimate paragraph is the way I do it. For example, if I want to use my
IShell
as anUIElement
(which is pretty normal) I declare the interface something like:Then in my implementation: