Reputation: 2647
I have a Grid with RowDefinitions defined in XAML that I need to change when going to snapped view in code, and so far I can only figure out how to remove them via:
RowDefinitionCollection defs = mainGrid.RowDefinitions;
defs.RemoveAt(0);
defs.RemoveAt(0);
Essentially I need to remove all definitions in snapped view (above code works) but then need to make the first row have a height of 140 and the second be "*" once it goes back into snapped. How would I add definitions with these characteristics?
Upvotes: 1
Views: 1197
Reputation: 48590
Simply
RowDefinitionCollection rdc = mainGrid.RowDefinitions;
rdc.Clear();
rdc.Add(new RowDefinition() { Height = new GridLength(140) });
rdc.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
Upvotes: 3
Reputation: 23784
Try:
RowDefinitionCollection defs = myGrid.RowDefinitions;
defs.Add(new RowDefinition() { Height = new GridLength(140) });
defs.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
Alternatively, you could have two Grids and just modify the Visibility as part of the visual state, then you're not pulling a lot of tedious UI manipulation into your code. The built-in Visual Studio templates use this technique for snapped view.
Upvotes: 1