I am beginner to WPF. There are three tabs in my application each tab with same functionality that is(Each tab has a grid bind to database). Grid in each tab is bind to different database table but functionality is same that is to add, delete, refresh edit. I wrote all functionality in Mainwindow.cs file.
I want that all code should be placed in three different classes. For Example.
There are three tables:
- Table A ---- bind to Grid named as grid.
- Table B ---- bind to Grid named as grida
- Table C ---- bind to Grid named as gridb
All functionality of operations Edit, Refresh, Add, Delete in MainWindow.cs file. Code lines 637. I want that : There should be three classes each defining their functionality separately. Problem is : How to pass grid name to these classes as it is defined in Mianwindow.Xaml! or is there any other better way to solve this.
I need your suggestions. Thank you.
You should investigate the MVVM pattern. This pattern is similar to MVC or MVP, but has become the standard way of creating WPF apps. It became standard because it uses WPF's strength in data binding. The idea is to create proper separation of concerns. You shouldn't be loading all your data in a
Window
. That is aView
. Instead, you should create aViewModel
that handles the loading of data (theModel
). YourView
would then bind to the data.For your application, you would have 1
View
class, and possibly 3 differentViewModel
classes (these can also be 1ViewModel
that takes a string as a constructor argument).Then, you would assign the appropriate
ViewModel
to theView
that handles the appropriate database connection.