0
votes

I am dynamically creating data grids in a tab window in WPF. I am having an issue with the data grid sizes, that are within the tabControl.

This is not an issue of the size of data within the data grid but the size of data grid itself.

I am looking to set the height and width to auto. This is simple in XAML but I am struggling to find any information to do it in the code which I need to do..

I have tired double.NaN but this does not seem to work....

Any help would be amazing!

I am using c#.

2
Are you sure problem is with the DataGrid and not with control which is containing it? - Haris Hasan
That's what it is though - it sets it to NaN. What are you trying to achive by setting your grid's Width to Auto? Height is always kind of auto. - user572559
I have a stack panel which is set to auto and a Tab control which is set to auto. Both within XAML. I am then creating a dynamic tab control and a datagrid..... I have tried setting them all to auto still does not seem to work... - user101010101
It would be useful if you can share your complete XAML - Haris Hasan
<StackPanel Height="Auto" Width="Auto"> <TabControl Name="Main_Tab_Control" Height="Auto" Width="Auto" /> </StackPanel> - user101010101

2 Answers

0
votes

Try

Height = new GridLength(1, GridUnitType.Auto);

0
votes

The problem is probably the StackPanel. It won't give the controls inside of it any more space than they "need" in the direction of it's orientation (so a vertical stack panel will only give the minimum required vertical space to each element). Try replacing it with a Grid or DockPanel.

In other words - controls in a vertical StackPanel will NOT expand to fill available vertical space, similarly for a horizontal StackPanel.