2012-07-10 33 views
0

我对WPF非常新,似乎无法让我的表单正确显示。我预计有6排。前三个应该有按钮,最后3个包含更多的网格。我是从NHibernate电子书下面的代码,但它似乎并没有正确显示。可能有人来看看这个代码,并提出任何可能的错误:WPF的新手。表单不能正确显示

<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> 

Window

+1

你能澄清“偏离中心”的截图,也许你想如何显示它的演绎? XAML文字墙伤害了我的眼睛;-) – 2012-07-10 08:24:58

+0

对不起。我正在努力。我已经解决了偏离中心的问题。那是网格比我想的主要形式更宽。我将得到一张照片,显示它目前的样子。 – CSharpened 2012-07-10 08:31:10

+0

我已经添加了一张图片。您可以看到3个按钮和一个网格可见,但最后两个网格不可见。对不起,但我只有油漆,它不会让我因为某种愚蠢的原因而裁剪 – CSharpened 2012-07-10 08:35:09

回答

1

比只有一排Grid.Row="5"Grid.RowSpan="2"杂散双重定义来定义,这两者你现在已经固定,唯一的代码,其他的是会影响定位的是所有虚假Margin的值。

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

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"

+0

我已经解决了这个问题,但窗口的外观没有改变。 – CSharpened 2012-07-10 08:33:16