在WPF中调整窗口

时间:2016-05-24 15:16:33

标签: c# .net wpf xaml

我开始使用WPF和C#开发我从Windows Forms中学到了一些东西,但是我遇到了一个不是如何解决的案例,我感谢我的导游。

我通过调用用户控件获取以下窗口菜单并将其绘制在框架中但看起来像。

Form

你看到User控件位于附加菜单之上,以最大化表格保持不变,你知道我可以解决吗?

这是主窗口的XAML。

<controls:MetroWindow x:Class="Laboratorio.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    mc:Ignorable="d"
    Title="Sistema de Control y Gestion de Laboratorio" 
    Height="650" Width="825"
    BorderThickness="0"    
    GlowBrush="Black"
    ResizeMode="CanResizeWithGrip"
    WindowTransitionsEnabled="False"
    Loaded="MainWindow_OnLoaded"
    WindowStartupLocation="CenterScreen">
<!-- Menu -->
<Grid>
    <Menu Name="MenuPrincipal">

    </Menu>
    <Frame Name="Contenido"></Frame>
</Grid>

这就是用户控件

<UserControl x:Class="Laboratorio.RegistroEquipo"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         Loaded="RegistroEquipo_OnLoaded"
         mc:Ignorable="d" 
         d:DesignHeight="450" d:DesignWidth="545">
<Grid>
    <GroupBox Header="Registro de Equipo">
        <Grid>
            <Label x:Name="serialLbl" Content="Serial:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="serialTxb" HorizontalAlignment="Left" Height="23" Margin="89,11,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140"/>
            <Label x:Name="descripcionLbl" Content="Descripcion:" HorizontalAlignment="Left" Margin="263,11,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="descripcionTxb" HorizontalAlignment="Left" Height="23" Margin="362,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140"/>
            <Label x:Name="marcaLbl" Content="Marca:" HorizontalAlignment="Left" Margin="10,49,0,0" VerticalAlignment="Top"/>
            <ComboBox x:Name="marcaCbb" HorizontalAlignment="Left" VerticalAlignment="Top" Width="140" Margin="89,49,0,0"/>
            <Label x:Name="claseLbl" Content="Clase:" HorizontalAlignment="Left" Margin="263,49,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="claseTxb" HorizontalAlignment="Left" Height="23" Margin="362,49,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140"/>
            <CheckBox x:Name="externoChk" Content="Externo" HorizontalAlignment="Left" Margin="10,91,0,0" VerticalAlignment="Top"/>
            <CheckBox x:Name="patronchk" Content="Patron" HorizontalAlignment="Left" Margin="171,91,0,0" VerticalAlignment="Top"/>
            <Label x:Name="articuloLbl" Content="Articulo:" HorizontalAlignment="Left" Margin="263,87,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="articuloTxb" HorizontalAlignment="Left" Height="23" Margin="362,87,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140"/>
            <Label x:Name="articuloLbl_Copy1" Content="Responsable:" HorizontalAlignment="Left" Margin="10,127,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="responsableTxb" HorizontalAlignment="Left" Height="23" Margin="89,127,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140"/>
            <TextBox x:Name="nombreTxb" HorizontalAlignment="Left" Height="23" Margin="263,127,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="239"/>
            <Label x:Name="observacionLbl" Content="Observacion:" HorizontalAlignment="Left" Margin="10,175,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="observacionTxb" HorizontalAlignment="Left" Height="79" Margin="10,223,0,0" TextWrapping="Wrap" AcceptsReturn="True" VerticalAlignment="Top" Width="503"/>
            <Button x:Name="registrarBtn" Content="Registrar" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="154,338,0,0" Click="Registrar_OnClick"/>
            <Button x:Name="salirBtn" Content="Salir" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="263,338,0,0"/>
        </Grid>
    </GroupBox>
</Grid>

2 个答案:

答案 0 :(得分:2)

转过来;

<!-- Menu -->
<Grid>
    <Menu Name="MenuPrincipal">

    </Menu>
    <Frame Name="Contenido"></Frame>
</Grid>

进入这个;

<!-- Menu -->
<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="*"/>
  </Grid.RowDefinitions>

    <Menu Name="MenuPrincipal"/>
    <Frame Grid.Row="1" Name="Contenido"/>

</Grid>

或者只需将Grid换成StackPanel,无论您喜欢哪种。

答案 1 :(得分:1)

它不是您的应用程序/ xaml,它是用于调试的Visual Studio工具。

当您的应用程序运行时,返回Visual Studio,转到Live Visual Tree,您可以关闭&#34;在应用程序中显示运行时工具&#34; (工具栏中的第一个按钮)

enter image description here