2014-02-19 337 views
1

我希望任何人可以幫助我,我使用WPF拆分窗口4的窗口,我建立了這個代碼分割窗口形成4個窗口

<Window x:Class="WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition /> 
      <ColumnDefinition /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition/> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <StackPanel Background="#feca00" Grid.Column="0" Grid.Row="0"> 
      <TextBlock FontSize="35" Foreground="#58290A" 
       TextWrapping="Wrap">4</TextBlock> 
     </StackPanel> 

     <GridSplitter ResizeDirection="Rows" 
       Grid.ColumnSpan="2" 
       HorizontalAlignment="Stretch" 
       VerticalAlignment="Bottom"/> 
     <Border CornerRadius="10" BorderBrush="#58290A" Grid.Column="0" Grid.Row="1" 
       BorderThickness="5"> 
      <TextBlock FontSize="25" Margin="20" Foreground="#FECA00" 
       TextWrapping="Wrap">3</TextBlock> 
     </Border> 
     <Border CornerRadius="10" BorderBrush="#58290A" Grid.Column="1" Grid.Row="0" 
       BorderThickness="5"> 
      <TextBlock FontSize="25" Margin="20" Foreground="#FECA00" 
       TextWrapping="Wrap">2</TextBlock> 
     </Border> 
     <Border CornerRadius="10" BorderBrush="#58290A" Grid.Column="1" Grid.Row="1" 
       BorderThickness="5"> 
      <TextBlock FontSize="25" Margin="20" Foreground="#FECA00" 
       TextWrapping="Wrap">1</TextBlock> 
     </Border> 

    </Grid> 
</Grid> 

我要建這個代碼由窗體不是WPF。 以同樣的方式在WPF中拆分屏幕。 我試圖建立它,但沒有找到結果,任何人都可以幫助我。

+0

您是否嘗試過使用SplitContainer? –

+0

是的,我找不到任何東西 – MARK

+1

我會建議您更新你的問題與你的勝利形式代碼,並描述它目前的工作原理,然後問一個關於你如何工作的具體問題。僅供參考,就像這樣,顯示期望行爲的屏幕截圖也可能有所幫助,因爲看起來您已經有了一個工作示例。 –

回答

0

首先,我想向您歡迎StackOverflow上。現在,我想指出,這是而不是這是一個網站,您可以在其中找到其他人爲您完成工作。 預計您特定問題來這裏清楚解釋說,問題是什麼,並表明已經有問題的代碼...它是適當來到這裏,說'如何你是否這樣做,因爲我不知道該怎麼辦?'。請在StackOverflow幫助中心的How do I ask a good question?頁面中找到更多信息。

現在轉到您的答案......記住我剛纔所說的,它會而不是適合我爲您提供一個完整的工作示例。因此,我想強調@MilanRavel對TableLayoutPanel的評論。由於WinForms沒有Grid元素來重新排列你的子UI控件,所以你必須要做TableLayoutPanel class,它做了一個類似的工作。

如果您不熟悉使用此控件,請參閱MSDN上的Walkthrough: Arranging Controls on Windows Forms Using a TableLayoutPanel頁面以獲取更多幫助。本頁面提供了許多有用的示例和更多示例的鏈接......我相信您將能夠確定要做什麼。

+0

感謝您的幫助 – MARK

-1

試試這個代碼.. !!

<Window x:Class="SpiltWindow.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="5" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="5" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <TextBlock FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">First</TextBlock> 
     <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" /> 
     <TextBlock Grid.Column="2" FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Second</TextBlock> 
    </Grid> 
    <GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" /> 
    <Grid Grid.Row="2"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="5" /> 
      <ColumnDefinition Width="*" /> 
     </Grid.ColumnDefinitions> 
     <TextBlock FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Third</TextBlock> 
     <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" /> 
     <TextBlock Grid.Column="2" FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Fourth</TextBlock> 
    </Grid> 
</Grid> 

+0

-1中使用TableLayoutPanel控件,以便*不讀*或回答問題。 – Sheridan

+0

請解釋爲什麼你的答案解決了問題中發佈的問題。 – Bandreid