Managing lots of overlapping controls in one Window in XAML
I'm working on a WPF application in which the client can select a device from a drop down list (ComboBox) and then have its specifications displayed to them in a DataGrid
control. I have made some 20 different DataGrids for the 20 different products and I've kept them overlapping each other (on top of one another) in a predefined Grid.Row
of my Window.xaml markup, with the Visibility of each DataGrid
set to Hidden, such that when a ComboBox
selection is changed I change the visibility of the DataGrid that belongs to that particular product selected from the ComboBox to MonitorDataGrid.Visibility = Visibility.Visible;
in my code behind.
It does the job but managing the layout of the Window 开发者_StackOverflowhas become really arduous and a catastrophe, especially when I want to change the styles or positions of the DataGrids. I was wondering what is the best way of managing the markup of lots of controls in one window occupying the same area?
Thanks in advance.
At first, Grid have AutoGenerateColumns property which automatically extracts columns from list given to it,
but if you have some extra properties in entity that you don't want to show, you can create templates in resourcedictionary, and keep only keys in the items of the DropDown and change grid template on itemchange
Showing and hiding grids is really the worst way to do this
Also this should help to do what you want
Hope this helps
精彩评论