2014-02-19 139 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