开发者

WPF "Insert" control per binding

开发者 https://www.devze.com 2023-03-24 20:14 出处:网络
I have a UserControl without Content, because the control which should be shown inside of the UserControl is created at runtime. I would like to solve this like follows, but don\'t know how to impleme

I have a UserControl without Content, because the control which should be shown inside of the UserControl is created at runtime. I would like to solve this like follows, but don't know how to implement it:

  1. Create a Control-variable in the ViewModel
  2. Set it at runtime when the content is created
  3. Bind a content pro开发者_运维百科perty (inside the UserControl) to that variable

The problem is, that I don't know how to bind to the control-variable.


Why just not to use ContentControl instead of UserControl and provide Content in runtime by introducing a DataTemplateSelector which able to provide right DataTemplate in runtime? You can encapsulate your Content-area controls in DataTemplates and select appropriate one in runtime.

0

精彩评论

暂无评论...
验证码 换一张
取 消