C#C
C#2y ago
44 replies
JJ

[WPF]How to binding in the UserControl.xaml at the same time load UserControl.xaml UI?

I'm using the wpf-ui template to use the wpf mvm pattern. I focused on 4 files
I want to use DashboardPage.xaml, DashboardPageViewModel.cs , User.xaml, UserViewModel.cs . I want to get the ui of the UserControl file User.xaml from the Page file DashboardPage.xaml.
By the way, I implemented a code that allocates datacontext to the behind code to implement a button-like control function in User.xaml. Of course, I implemented the same code that allocates DataContext to the DashboardPage.xaml.cs behind code. The problem is that the code implemented by User.xaml.cs causes the "Object reference not set to an instance of an object." error.
I wonder why the problem occurred.

*picture 1 is error cature.
**picture2 is that if annotate ViewModel assign part and DataContext assign part in the User.xaml.cs , then no happened error.
but this is not what i want. I wanna implement control at the UserControl.xaml ( User.xaml)


How to solve this problem. and Why did the error occur?
below is code.
https://github.com/Jlim01/UiDesktopApp1.git
image.png
image.png
GitHub
Contribute to Jlim01/UiDesktopApp1 development by creating an account on GitHub.
GitHub - Jlim01/UiDesktopApp1
Was this page helpful?