WPF的新成员。表单显示不正确

WPF的新成员。表单显示不正确,wpf,layout,gridview,Wpf,Layout,Gridview,我对WPF非常陌生,似乎无法正确显示我的表单。我希望有6排。前三个应该有按钮,后三个包含更多的网格。我在遵循NHibernate电子书中的代码,但它似乎没有正确显示。是否有人可以查看此代码并建议任何可能的错误: <av:Window x:Class="Chapter2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.

我对WPF非常陌生,似乎无法正确显示我的表单。我希望有6排。前三个应该有按钮,后三个包含更多的网格。我在遵循NHibernate电子书中的代码,但它似乎没有正确显示。是否有人可以查看此代码并建议任何可能的错误:

<av:Window x:Class="Chapter2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Title="Product Inventory" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="493" d:DesignWidth="566" SizeToContent="WidthAndHeight">
<av:Grid>
    <av:Grid.RowDefinitions>
        <av:RowDefinition Height="auto" />
        <av:RowDefinition Height="auto" />
        <av:RowDefinition Height="auto" />
        <av:RowDefinition Height="*" />
        <av:RowDefinition Height="*" />
        <av:RowDefinition Height="*" />
    </av:Grid.RowDefinitions>
    <av:Button x:Name="btnCreateDatabase" Content="Create Database" Click="BtnCreateSessionFactoryClick"/>
    <av:Button x:Name="btnCreateSessionFactory" Content="Create Session Factory" Click="BtnCreateSessionFactoryClick" av:Grid.Row="1"/>
    <av:Button x:Name="btnCreateSession" Content="Create Session" Click="BtnCreateSessionClick" av:Grid.Row="2" />
    <av:Grid x:Name = "CategoryGrid" av:Grid.Row="3" Margin="0 10 0 0">
        <av:Grid.ColumnDefinitions>
            <av:ColumnDefinition Width="Auto"/>
            <av:ColumnDefinition Width="*"/>
        </av:Grid.ColumnDefinitions>
        <av:Grid.RowDefinitions>
            <av:RowDefinition Height="Auto" />
            <av:RowDefinition Height="Auto" />
            <av:RowDefinition Height="Auto" />
        </av:Grid.RowDefinitions>
        <av:TextBlock Text="Category Name:"/>
        <av:TextBlock Text="Category Description:" av:Grid.Row="1"/>
        <av:TextBox x:Name="txtCategoryName" av:Grid.Column="1"/>
        <av:TextBox x:Name="txtCategoryDescription" av:Grid.Row="1" av:Grid.Column="1"/>
        <av:Button x:Name="btnAddCategory" Content="Add Category" av:Grid.Row="2" Click="BtnAddCategoryClick" />
    </av:Grid>
    <av:Grid x:Name = "ProductGrid" Margin="1,0,-1,131" av:Grid.Row="4">
        <av:Grid.ColumnDefinitions>
            <av:ColumnDefinition Width="Auto"/>
            <av:ColumnDefinition Width="*"/>
        </av:Grid.ColumnDefinitions>
        <av:Grid.RowDefinitions>
            <av:RowDefinition Height="Auto" />
            <av:RowDefinition Height="Auto" />
            <av:RowDefinition Height="Auto" />
        </av:Grid.RowDefinitions>
        <av:TextBlock Text="Category Name:"/>
        <av:TextBlock Text="Category Description:" av:Grid.Row="1"/>
        <av:TextBox x:Name="txtProductName" av:Grid.Column="1"/>
        <av:TextBox x:Name="txtProductDescription" av:Grid.Row="1" av:Grid.Column="1"/>
        <av:Button x:Name="btnAddProduct" Content="Add Product" av:Grid.Row="2" Click="BtnAddCategoryClick" />
    </av:Grid>
    <av:Grid x:Name = "LoadCategoryGrid" av:Grid.Row="5" Margin="1,0,-1,0" >
        <av:Grid.ColumnDefinitions>
            <av:ColumnDefinition Width="278"/>
            <av:ColumnDefinition Width="265"/>
        </av:Grid.ColumnDefinitions>
        <av:Grid.RowDefinitions>
            <av:RowDefinition Height="Auto" />
        </av:Grid.RowDefinitions>
        <av:Button x:Name="btnLoadCategories" Content="Load Categories"  VerticalAlignment="Top" Click="BtnLoadCategoriesClick" Margin="0,188,186,0" />
        <av:ListBox x:Name="lstCategories"  Margin="52,188,-55,-10" av:Grid.Column="1" />
    </av:Grid>
</av:Grid>


最后一个网格与第5行的网格重叠,线条为:

<av:Grid x:Name = "ProductGrid" Margin="-1,2,1,130" av:Grid.Row="5">
<av:Grid x:Name = "LoadCategoryGrid" av:Grid.Row="5" Margin="3,73,-3,128" >


将两个网格放置在同一网格行,查看具有相同值的
av:grid.row
附加属性。要将其中一个移动到自由位置,必须更改为:
av:Grid.Row=“4”

,而不是
Grid.Row=“5”
Grid.RowSpan=“2”
的双重定义,只定义了一行,这两行现在都已修复,影响定位的唯一其他代码是所有虚假的
Margin


除此之外,XAML看起来还不错。

你能用屏幕截图和你希望它如何显示的格式副本来澄清“偏心”吗?XAML文本的墙刺痛了我的眼睛;-)是的,很抱歉。我当时正在准备搭便车。我已经解决了偏离中心的问题。这是网格比我认为的主要形式更宽。我将得到一张显示当前外观的图片。我现在添加了一张图片。您可以看到3个按钮和一个网格可见,但最后两个网格不可见。很抱歉,这张图片很差,但我只有画画,出于一些愚蠢的原因,它不允许我裁剪。底部网格为列表框指定了2行,但只定义了1行。我已经创建了一个答案,以避免未来的访问者浏览评论。我已经解决了这个问题,但窗口的外观没有改变。