2014-09-21 79 views
0

我的问题是可见的图像“wrong.png” 我已经创建了一个应该有3列,并停靠在底部的堆叠面板,以及它的内容,在这案件是3个按钮。看着“wrong.png”,这对我来说并不好。停靠在底部的堆栈面板,并添加列定义

我已经添加了另一个图像“desired.png”,它显示了我想实现的目标。 感谢您提供任何帮助。

这里是代码:

<Window x:Class="EnerMedit.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="499.88" Width="702"> 
<DockPanel LastChildFill="True"> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 

     </Grid.ColumnDefinitions> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
      <RowDefinition Height="auto" /> 
     </Grid.RowDefinitions> 

     <Label Content="Seavaro" Grid.Row="0" FontSize="18" /> 

     <Label Content="Date" Grid.Row="1" /> 
     <DatePicker Grid.Row="2" Name="datepicker" Background="Honeydew" /> 

     <Label Content="Note:" FontWeight="ExtraBold" Grid.Row="3" Margin="0 10 0 0" /> 
     <RadioButton Content="Meditation" Name="mediNote" Margin="50 17 0 0" Grid.Row="3" /> 
     <RadioButton Content="Energy" Name="energyNote" Margin="150 17 0 0" Grid.Row="3" /> 
     <RadioButton Content="Both" Name="bothNoteButton" Margin="250 17 0 0" Grid.Row="3" Checked="bothNoteButton_Checked" /> 
     <TextBox Grid.Row="4" Background="Honeydew" /> 

     <Separator Width="auto" Grid.Row="5" Margin="0 20 0 20" Background="GreenYellow"/> 

     <TextBox Grid.Row="6" MinHeight="150" TextWrapping="Wrap" Background="Honeydew" IsReadOnly="True" /> 
     <CheckBox Content="Done" Name="doneCheck" Grid.Row="7" Margin="5 7 0 0" /> 

     <Label Content="Akana" Grid.Column="1" Grid.Row="0" FontSize="18" Margin="10 0 0 0" /> 


     <CheckBox Content="Check all" Grid.Column="1" Grid.Row="1" Margin="200 7 0 0" Name="IsCheckedCheckAll" 
        Checked="IsCheckedCheckAll_Checked" Unchecked="IsCheckedCheckAll_Checked" /> 


     <Label Content="Excercise 1" Grid.Column="1" Grid.Row="2" FontFamily="Comic Sans MS" Margin="10 0 0 0" /> 
     <CheckBox Name="Exc1" Grid.Column="1" Grid.Row="2" Margin="200 7 0 0" IsChecked="{Binding IsChecked, ElementName=IsCheckedCheckAll, Mode=OneWay}" /> 

     <Label Content="Excercise 2" Grid.Column="1" Grid.Row="3" FontFamily="Comic Sans MS" Margin="10 0 0 0" /> 
     <CheckBox Name="Exc2" Grid.Column="1" Grid.Row="3" Margin="200 7 0 0" IsChecked="{Binding IsChecked, ElementName=IsCheckedCheckAll, Mode=OneWay}" /> 

     <Label Content="Excercise 3" Grid.Column="1" Grid.Row="4" FontFamily="Comic Sans MS" Margin="10 0 0 0" /> 
     <CheckBox Name="Exc3" Grid.Column="1" Grid.Row="4" Margin="200 7 0 0" IsChecked="{Binding IsChecked, ElementName=IsCheckedCheckAll, Mode=OneWay}" /> 

     <Label Content="Excercise 4" Grid.Column="1" Grid.Row="5" FontFamily="Comic Sans MS" Margin="10 0 0 0" /> 
     <CheckBox Name="Exc4" Grid.Column="1" Grid.Row="5" Margin="200 7 0 0" IsChecked="{Binding IsChecked, ElementName=IsCheckedCheckAll, Mode=OneWay}" /> 

     <Label Content="Excercise 5" Grid.Column="1" Grid.Row="6" FontFamily="Comic Sans MS" Margin="10 0 0 0" /> 
     <CheckBox Name="Exc5" Grid.Column="1" Grid.Row="6" Margin="200 07 0 0" IsChecked="{Binding IsChecked, ElementName=IsCheckedCheckAll, Mode=OneWay}" />        
    </Grid> 

    <StackPanel VerticalAlignment="Bottom"> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions>  

       <Button Content="Add" Name="SubmitButton" Grid.Column="0" Height="23" IsEnabled="{Binding ElementName=doneCheck, Path=IsChecked}" /> 
       <Button Content="Labaci recardo" Name="GetMedButton" Grid.Column="1" Grid.Row="9" /> 
       <Button Content="Supa recardo" Name="GetEnegButton" Grid.Column="2" />    
     </Grid> 
    </StackPanel> 
</DockPanel>     

enter image description hereenter image description here

+0

尝试将您的'StackPanel'放在更高一层。 – AgentFire 2014-09-21 11:01:06

+0

在我将它移出之前,我曾尝试过。按钮仍然浮动在顶部,但是这次在右侧,并且将只有两列,因为在该级别上已经有另一个列定义了。 – user1960836 2014-09-21 11:06:54

回答

1

您需要从StackPanel删除第二DockPanel父母,你也需要交换造成StackPanelGrid的地方。只有你的主要DockPanel将按照你的预期布置你的元素。

<Window x:Class="WpfApplication2.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="700" Width="800"> 
    <DockPanel LastChildFill="True"> 
     <StackPanel DockPanel.Dock="Bottom"/> 
     <Grid/> 
    </DockPanel> 
</Window> 
+0

我编辑了xaml代码。这是你的意思?这是行不通的。会发生什么,是多3个列被添加到右上角,并且按钮仍然聚集在3列中的第一列 – user1960836 2014-09-21 15:06:43

+1

@ user1960836 **否,这不是我的意思。**首先进入堆栈面板,然后是网格,更接近我的答案。 – AgentFire 2014-09-21 15:39:32

+0

谢谢,这有助于对齐,他们现在水平显示。现在唯一的事情是,第三列仍然在最右边创建,这就是堆叠面板的位置。我编辑了代码。 再次感谢 – user1960836 2014-09-21 15:56:14

相关问题