The end result that I'm imagining is that I have an XML file that defines the layout of certain parts of the UI. At execution, (1) I read the XML file in and (2) build out the controls and assign their DataContexts to the associated ViewModels. Can anyone share any examples of part (2) that they've come across or perhaps show one?
Asked
Active
Viewed 63 times
0
-
1I am not sure that [this](http://stackoverflow.com/questions/15532772/c-sharp-load-xaml-file-at-runtime) or [this](http://stackoverflow.com/questions/9021677/loading-xaml-at-runtime-using-the-mvvm-pattern-in-wpf) are exact duplicates to your question, but nonetheless you may want to take a look. – Eugene Podskal Jul 28 '14 at 06:30
-
1google for datatemplates and datatemplateselector – user3596113 Jul 28 '14 at 06:34
1 Answers
2
isnt it much easier to define DateTemplates for your viewmodels.
<DataTemplate DataType="{x:Type MyViewmodel}" >
<view:MyViewmodelView/>
</DataTemplate>
then create your Viewmodels "dynamic" and assign the Viewmodels to a ContentControl? then WPF handle your how your Viewmodel is to render.
<ContentControl Content="{Binding MyWorkspace}"/>
MainViewmodel
public object MyWorkspace {get;set;}
this.MyWorkspace = new MyViewmodel();

blindmeis
- 22,175
- 7
- 55
- 74