I want to be able to load items in System.Windows.Controls using late binding.
I can do it with dlls that i can load remotely like this:
private void Button_Click(object sender, RoutedEventArgs e)
{
panel1.Children.Clear();
WebClient c = new WebClient();
c.OpenReadCompleted += new OpenReadCompletedEventHandler(c_OpenReadCompleted);
c.OpenReadAsync(new Uri("DynamicXapDataGrid_CS.xap", UriKind.Relative));
}
void c_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(e.Result, null), new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd();
XElement deploy = XDocument.Parse(appManifest).Root;
List<XElement> parts = (from assemblyParts in deploy.Elements().Elements()
select assemblyParts).ToList();
Assembly asm = null;
foreach (XElement xe in parts)
{
string source = xe.Attribute("Source").Value;
AssemblyPart asmPart = new AssemblyPart();
StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(e.Result, "application/binary"), new Uri(source, UriKind.Relative));
if (source == "DynamicXapDataGrid_CS.dll")
{
asm = asmPart.Load(streamInfo.Stream);
}
else
{
asmPart.Load(streamInfo.Stream);
}
}
panel1.DataContext = FakeData.GetCustomers(LastNameSearch.Text);
UIElement myData = asm.CreateInstance("DynamicXapDataGrid_CS.Page") as UIElement;
panel1.Children.Add(myData);
panel1.UpdateLayout();
}
the problem comes when i want to load, say a Grid.
Assembly asm = Assembly.GetCallingAssembly();
UIElement element = null;
try { element = asm.CreateInstance("System.Windows.Controls.Grid") as UIElement; } catch { }
is always null. I assume that i may need the fully qualified name for Grid, but i have been Googling this for hours now with no solution. Any help would be appreciated.