WPF网格行高度与我输入的高度不匹配

时间:2009-12-23 01:55:49

标签: wpf grid height

我一整天都在拔头发。出于某种原因,当我使用一些自定义控件设置网格时,网格行的实际高度会发生变化,并且不会费心使用我给出的高度值。我原本以为是因为我在代码中加载了自定义控件,但即使我将自定义控件移出问题依然存在。这就是我对xaml的看法

<Window x:Class="Pokemon_Planner.PokePlan"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PokePlan" Height="600" Width="800">
<Grid x:Name="myGrid">

    <Grid.RowDefinitions>
        <RowDefinition Height="25" Name="row0"></RowDefinition>
        <RowDefinition Height="Auto" Name="row1"></RowDefinition>
        <RowDefinition Height="48" Name="row2"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="0">
        <ComboBox Name="cmbSort" Width="100">
            <ComboBoxItem Content="Name"></ComboBoxItem>
            <ComboBoxItem Content="Type"></ComboBoxItem>
            <ComboBoxItem Content="Element"></ComboBoxItem>
            <ComboBoxItem Content="BP"></ComboBoxItem>
            <ComboBoxItem Content="Min Damage"></ComboBoxItem>
            <ComboBoxItem Content="Max Damage"></ComboBoxItem>
        </ComboBox>
        <Button Name="btnSort" Click="btnSort_Click">Sort</Button>
        <Button Name="btnRefresh" Click="btnRefresh_Click">Refresh</Button>
        <Button Name="btnFilter">Filter</Button>
    </StackPanel>
    <StackPanel Grid.Column="0" Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Top" Name="stkMoveSet1">

    </StackPanel>
    <StackPanel Grid.Column="0" Grid.Row="3" Orientation="Horizontal" Name="stkMoveSet2">

    </StackPanel>
    <ScrollViewer Grid.Row="1" Grid.Column="1" Grid.RowSpan="6" Height="Auto" Name="scrollViewerMoves" >
        <StackPanel Grid.Row="1" Grid.Column="1" Grid.RowSpan="6" Name="moveStackPanel"></StackPanel>
    </ScrollViewer>
</Grid>

设置为高度为48的行仍设置了该高度,但“实际高度”为446,这仍然是我的网格。数字有所不同,我在设定数字和自动之间尝试了很多不同的组合,但我似乎无法让这一个窗口正常运行。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可能希望将“row2”网格行高度定义更改为“auto”,并将“scrollViewerMoves”滚动查看器的高度设置为48。像这样的Smth:

...
<RowDefinition Height="Auto" x:Name="row2"></RowDefinition>
...
<ScrollViewer Grid.Row="1" Grid.Column="1" Height = "48" Name="scrollViewerMoves" >
...

我想这应该做你需要的, 问候

相关问题