开发者

Managing lots of overlapping controls in one Window in XAML

开发者 https://www.devze.com 2023-04-06 08:16 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号