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

发布于 2024-08-16 01:24:52 字数 2588 浏览 1 评论 0原文

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

I've been pulling my hair out all day on this. For some reason when I set up my grid while I'm using some custom controls the actual height of the grid rows changes around and doesn't bother to use the height values that I give it. I originally thought it was because I was loading in custom controls in the code, but even when I take the custom controls out the problem remains. Here's what I have for the 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>

The row that was set to have a height of 48 still had that height set, but the 'actual height' was 446 which is still really screwing my grid up. The numbers vary and I've tried a lot of different combinations between set numbers and auto but I can't seem to get this one window to behave correctly. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2024-08-23 01:24:52

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

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

我想这应该可以满足你的需要,
问候

you might want to change "row2" grid row height definition to "auto" and set height to 48 for the "scrollViewerMoves" scrollviewer. Smth like this:

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

I guess this should do what you need,
regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文