C# 带网格的WPF项目

C# 带网格的WPF项目,c#,.net,wpf,C#,.net,Wpf,我有这个Windows应用程序: <Window x:Class="PlayTube.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="800" Width="1400"> <Grid B

我有这个Windows应用程序:

<Window x:Class="PlayTube.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="800" Width="1400">
<Grid Background="#FFD86F6F">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid Height="70" Background="#FF9A9A9A">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBox Grid.Column="1" Height="25" Width="200" Name="SearchTextBox" />
        <Button Grid.Column="2" Height="25" Width="80" Content="Search" Click="Button_Click" />
    </Grid>

    <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" MaxWidth="250" />
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="300" MaxWidth="350"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Grid Background="#FFFFFF89">

        </Grid>

        <GridSplitter HorizontalAlignment="Right" 
              VerticalAlignment="Stretch" 
              Grid.Column="1" ResizeBehavior="PreviousAndNext"
              Width="5" Background="#FFBCBCBC" />

        <Grid Background="#FF05BECB" Grid.Column="2">

        </Grid>

        <GridSplitter HorizontalAlignment="Right" 
              VerticalAlignment="Stretch" 
              Grid.Column="3" ResizeBehavior="PreviousAndNext"
              Width="5" Background="#FFBCBCBC"/>

        <Grid Background="#FF4E04A7" Grid.Column="4">
            <MediaElement Stretch="Fill" />
        </Grid>
    </Grid>
</Grid>


如您所见,我有3个网格,我想知道是否可能从一个类管理每个网格,因为我不希望所有逻辑都在这个主Windows类中。

右键单击您的项目,选择“添加”子菜单,然后选择“用户控件”,您应该会看到这个对话框

为控件指定一个名称,然后单击“确定”

构建您的项目并查看工具箱,您应该在顶部看到您添加的新用户控件将在那里

将此项拖动到网格的内容中,它将为您设置所有内容

在这样做之后,我的窗户现在看起来像

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <local:UserControl1 HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100"/>
    </Grid>
</Window>


您是说希望每个网格的内容来自另一个文件吗?像一个用户控件?我对.net的所有东西都是新手,我尝试了UserControl,但是当我创建一个时,它没有给我一个用于编辑的xaml文件。我做了所有这些,当我添加
时,你在添加用户控件后构建了应用程序吗?设计师对这样的事情可能有点奇怪。