Dynamicly putting Object to many visual parents in WPF
I want to create my own usercontrol which will take some FrameworkElement as parameter (as Content) and then it will didplay it on few copies (how much? it depends) Anyway copies has to be binded to their VM. Single copy will be probably a StackPanel with few binded buttons and TextBoxes. So it will look like this:
<MyControl> <Panel with stuff in it/> </MyControl>
Now in my control I hot ItemsControl and I am dynamicly putting there items. But one content (stack panel for example) can only has one parent so it doesn't work. How can I achive this? I heard that DataTemplates can help me but I don't know how. Also I wander if I can't do something like this:
<开发者_JAVA百科MyControl> <ViewModel of Panel with stuff/> </MyControl>
You need to take a DataTemplate
property that contains the FrameworkElement
(s), then create ContentPresenter
s in the control, with their Content
set to the piece of ViewModel and their ContentTemplate
set to your DataTemplate
property.
精彩评论