本文介绍了评估Usercontrol继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我有处理Wpf UserControls的方法.

问题在于某些用户控件实现了接口"MyInterface"
某些用户控件则没有.

我需要从具有该实现的用户控件中调用"MyInterface"方法,但是由于可能存在没有接口方法的用户控件,因此我无法盲目地转换用户控件,例如.像这样:

Hi all!

I have method which handles Wpf UserControls.

The problem is that some of usercontrols implement interface "MyInterface"
and some usercontrols does not.

I need to call "MyInterface" methods from usercontrols who has that implementation, but since there could be usercontrols without interface method i cannot convert usercontrol blindly eg. like this:

var temp = (userControl as MyInterface);
temp.MyInterfaceMethod();



希望你有主意:)

干杯!



Hope you got idea :)

Cheers!

推荐答案

if(userControl is MyInterface){
    var temp = (userControl as MyInterface);
    temp.MyInterfaceMethod();
}


这篇关于评估Usercontrol继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 00:39