Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I can't seem to see why the View is not displaying. I have tried using both the ContentControl and the ContentPresenter.
If I add the datatemplate within the MakeControl (view) and bind to the Grid DataContext it works. I am trying to bind from the MainWindowViewModel.
C#
public MainWindowViewModel()
{
       MakeViewModel mMakeViewModel = new MakeViewModel();
       this.ViewModels .Add(mMakeViewModel);
}

XML
<Window......
    <Window.Resources>
        <DataTemplate DataType="{x:Type vm:MakeViewModel}">
            <vw:MakeControl/>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Border >
            <ContentControl Content="{Binding ViewModels}" />
        </Border>
    </Grid>
<Window/>


Behind Code on the Window:
C#
base.OnStartup(e);
CallWindow mCallWindow = new CallWindow();
var mViewModel = new MainWindowViewModel();
mCallWindow.DataContext = mViewModel ;
mCallWindow.Show();
Posted
Updated 2-Jul-10 5:08am
v2
Comments
Sandeep Mewara 2-Jul-10 11:08am    
Use PRE tags to format code part from next time please.

1 solution

Not quite understand what you are trying to achieve here... Your ContentControl has its ContentProperty binded to a some kind of collection of MakeViewModel but you have the DataTemplate only for the type MakeViewModel, not its collection... If you are trying to show the collection of MakeViewModel you should or define the DataTemplate to show the collection (not only one item) or use ItemsControl instead of the ContentControl.

Hope this helps, but if does not, clarify the question so I can help you further.

Best regards.
Raul Mainardi Neto
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900