I have created usercontrol instance into separate appdomain and convert it to INativeHandleContract as per addin framework guideline, and I am able to pass reference of framework instance into host application domain. When I convert INativeHandleContract back to UIElement in the host application appdomain, I am unable to cast the UIElement to my custom interface type.
Can anyone please tell me whether it is possible to convert Framework element into userControl or cast it to my custom interface?
here's a part of the code:
public INativeHandleContract GetControl(string AssemblyName, string strFullNamespaceName)
{
var assembly = Assembly.LoadFrom(m_strAssemblyDirectory + AssemblyName);
var type1 = typeof(IUPiAssemblyProcedure);
var type2 = typeof(IUPiCardProcedure);
var type3 = typeof(IUPiDatabaseFrame);
var type4 = typeof(IUPiUserFrame);
var t = from T in assembly.GetTypes() where type1.IsAssignableFrom(T) || type2.IsAssignableFrom(T) || type3.IsAssignableFrom(T) || type4.IsAssignableFrom(T) select T;
if (t.Count<Type>() == 0) return null;
var tName = t.First<Type>().FullName;
return FrameworkElementAdapters.ViewToContractAdapter((FrameworkElement)assembly.CreateInstance(tName));
}
public void LoadUserControl(INativeHandleContract contract)
{
var uControl = FrameworkElementAdapters.ContractToViewAdapter(contract);
var t = uControl.GetType();
t.GetMethod("methodName");
...
}
My goal is to Invoke some methods defined in custom interface, implemented by one of the types in the assembly I've loaded.
Regards Tihomir Blagoev