问题
I'm doing some stuff in WPF.
I have a ComboBox with many Types. After selecting a concrete type, I want to be able to Load a particular UserControl (with many TextBoxes etc.) respecting the type in a defined region on my WPF Window.
How to do that? Is there anything like
LoadControl() and load it into a PlaceHolder in ASP.NET? And what's the best way of doing this?
Thanks.
回答1:
You should create a DataTemplate for each type. See Different item template for each item in a WPF List for more information.
回答2:
What about:
object o = Activator.CreateInstance(type);
myUserControl.PubliclyExposedContainer.Content = o;
Not really sure why you'd go to the trouble of creating a DataTemplate for each type.
来源:https://stackoverflow.com/questions/1164738/wpf-load-control-question