我想改变我的GridView的高度,在XAML中我使用以下代码:
<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>但是,如果我想动态地这样做? 我试过了:
Style style = new Style(); style.TargetType = typeof(GridViewColumnHeader); style.Setters.Add(new Setter(GridViewColumnHeader.HeightProperty, 155)); GView.ColumnHeaderContainerStyle = style;但是我有一个ArgumentException(值155不是有效值)。 为什么? 我怎么解决这个问题? 谢谢。
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.
最满意答案
FrameworkElement.Height需要一个double值,因此您需要将155作为double传递给:
style.Setters .Add(new Setter(GridViewColumnHeader.HeightProperty, 155d));要么
style.Setters .Add(new Setter(GridViewColumnHeader.HeightProperty, 155.0));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));更多推荐
style,GridViewColumnHeader,电脑培训,计算机培训,IT培训"/> <meta name="de
发布评论