How to instantiate DataContext object in XAML

后端 未结 4 1458
独厮守ぢ
独厮守ぢ 2020-12-29 03:46

I want to be able to create an instance of the DataContext object for my WPF StartupUri window in XAML, as opposed to creating it code and then setting the

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 04:04

    If you need to set the DataContext as same control class:

        
    
    

    use RelativeSource binding.

    or just

         
    
    < new instance of any viewModel here....>
    
        
    

    If want to assign an instance of different class than itself.

提交回复
热议问题