How to pass XAML grid name?

294 views Asked by At

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:

  1. Table A ---- bind to Grid named as grid.
  2. Table B ---- bind to Grid named as grida
  3. 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.

1

There are 1 answers

2
Abe Heidebrecht On

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 a View. Instead, you should create a ViewModel that handles the loading of data (the Model). Your View would then bind to the data.

For your application, you would have 1 View class, and possibly 3 different ViewModel classes (these can also be 1 ViewModel that takes a string as a constructor argument).

Then, you would assign the appropriate ViewModel to the View that handles the appropriate database connection.