WPF Load Control question

余生颓废 提交于 2019-12-07 21:57:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!