2014-09-21 82 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

相關問題