我是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>
答案 0 :(得分:1)
最后一个网格与第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"
答案 1 :(得分:1)
除了定义了只有一行的Grid.Row="5"
和Grid.RowSpan="2"
的迷路双重定义之外,你现在已经修复了这两行,唯一会影响定位的其他代码就是所有假的{{ 1}}值。
除此之外,XAML看起来很好。