Reputation: 10499
I want to change the height of my GridView, in XAML i use the following code:
<Window.Resources>
<Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Height" Value="45"></Setter>
</Style>
</Window.Resources>
<ListView x:Name="LView">
<ListView.View>
<GridView x:Name="GView" ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}"></GridView>
</ListView.View>
</ListView>
But if I want to do this dynamically? I tried:
Style style = new Style();
style.TargetType = typeof(GridViewColumnHeader);
style.Setters.Add(new Setter(GridViewColumnHeader.HeightProperty, 155));
GView.ColumnHeaderContainerStyle = style;
But I have an ArgumentException (the value 155 is not a valid value). Why? How can i solve this problem? Thanks.
Upvotes: 4
Views: 3897
Reputation: 139788
FrameworkElement.Height expects a double value so you need to pass 155 as a double with:
style.Setters
.Add(new Setter(GridViewColumnHeader.HeightProperty, 155d));
Or
style.Setters
.Add(new Setter(GridViewColumnHeader.HeightProperty, 155.0));
Upvotes: 4