What is the differnce between DataTemplate and DataContext in WPF?

Posted by Ashish Ashu on Stack Overflow See other posts from Stack Overflow or by Ashish Ashu
Published on 2010-03-09T09:34:10Z Indexed on 2010/03/09 9:36 UTC
Read the original article Hit count: 1013

Filed under:
|
|

I can set the relationship b/w View Model and view through following DataContext syntax:

 <UserControl.DataContext>
    <view_model:MainMenuModel />
</UserControl.DataContext>

And I can also set the relationship b/w View Model and view through following DataTemplate syntax:

    <DataTemplate
        DataType="{x:Type viewModel:UserViewModel}">
        <view:UserView />
    </DataTemplate>

Please let me know what is the difference between the two ? Is the second XAML does not set the data context of a view ?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-controls