【问题标题】:WPF grid row height doesn't match the height that I inputWPF 网格行高与我输入的高度不匹配
【发布时间】:2010-12-29 08:20:56
【问题描述】:

我整天都在为此烦恼。出于某种原因,当我在使用一些自定义控件时设置网格时,网格行的实际高度会发生变化,并且不会费心使用我给它的高度值。我最初认为这是因为我在代码中加载了自定义控件,但即使我将自定义控件取出,问题仍然存在。这是我为 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,这仍然真的把我的网格搞砸了。数字各不相同,我在 set numbers 和 auto 之间尝试了很多不同的组合,但我似乎无法让这个窗口正常运行。有什么想法吗?

【问题讨论】:

    标签: wpf grid height


    【解决方案1】:

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

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

    我想这应该可以满足您的需求, 问候

    【讨论】:

    • 非常感谢,谢尔盖。这让我走上了正确的道路。滚动查看器不在第 2 行,所以我更改了第 2 行和第 3 行的堆栈面板,效果很好!现在的问题似乎是滚动查看器,因为它使第 1 行变得很大,因为其他人都在控制之下。我尝试改变它的大小,但这并没有多大作用,然后我摆脱了行跨度并且事情正确排列。除了滚动查看器本身。我希望滚动查看器选择从第 1 行跨越到屏幕底部,但没有行跨度,当第 2 行启动时它是不可见的。有什么解决办法吗?
    • 我猜想把滚动查看器的高度放回“自动”应该让它跨行,我猜是这样的:..ScrollViewer Grid.Row="1" Grid.Column="1" Grid。 RowSpan="6" Height="Auto"..
    • 它必须在 Windows 上工作并且对我来说工作正常;解析 pdf 文件可能会出现问题,但通常您会从 gs 收到一条错误消息,其中会解释丢失或损坏的内容;你能把你的 pdf 文件贴在文件共享服务上,这样我可以尝试转换它
    • 奇怪的是,删除 Height="Auto" 并将其留空就可以解决问题。谢谢你,快乐(你选择的假期)!
    • thnx,我想嵌套网格可能会满足您的需求
    猜你喜欢
    • 1970-01-01
    • 2017-06-01
    • 2013-03-07
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 2019-12-25
    相关资源
    最近更新 更多