2013-10-22 1 views
0

두 개의 "UserControl"각 UserControl 높이가 다릅니다.이 UserControl 동일한 창에서 넣을 수 있지만 다른 시간, 높이 UserControl 높이에 따라 동적으로 높이 창이 어떻게 변경됩니다.UserControl에 따라 WPF에서 높이 윈도우를 변경하는 방법은 무엇입니까?

최초의 UserControl이다 :

<UserControl x:Class="UserControl1" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      Height="auto" Width="auto"> 
<Grid Height="auto" Width="360" ..... > 
    <Grid VerticalAlignment="Center" > 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto" MinHeight="20.8"/> 
        <RowDefinition Height="Auto" MinHeight="20"/> 
        <RowDefinition Height="Auto" MinHeight="18.4"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto" MinHeight="20.8"/> 
        <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/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
       </Grid.RowDefinitions> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="33*"/> 
        <ColumnDefinition Width="17*"/> 
       </Grid.ColumnDefinitions> 
       <TextBlock Text="xx" Grid.Column="1" Grid.Row="0" ......./> 
       <TextBlock Text="yyy" Grid.Column="1" Grid.Row="1" ...... /> 
               ............ 
               ............ 
    </Grid> 
</Grid> 
</UserControl> 

Secound UserControl을입니다

<UserControl x:Class="UserControl2" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      Height="auto" Width="auto"> 
<Grid Height="auto" Width="360" ..... > 
    <Grid VerticalAlignment="Center" > 
       <Grid.RowDefinitions> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
        <RowDefinition Height="Auto"/> 
       </Grid.RowDefinitions> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="33*"/> 
        <ColumnDefinition Width="17*"/> 
       </Grid.ColumnDefinitions> 
       <TextBlock Text="xx" Grid.Column="1" Grid.Row="0" ......./> 
       <TextBlock Text="yyy" Grid.Column="1" Grid.Row="1" /> 
               ............ 
    </Grid> 
</Grid> 
</UserControl> 
MainWindow를

:

<Window 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     x:Class="MainWindow" 
     Title="Home" Height="550"*** Width="700" WindowStartupLocation="CenterScreen" ....> 
<Grid Name="Move"> 
    <Button Content="xxx" Height="28" TextBlock.FontSize="15" Name="btn1" Click="click1"/> 
    <Button Content="yyy" Grid.Row="1" Name="btn2" Click="click2"/> 
</Grid> 
</Window> 

코드 MainWindow를 뒤에 :

private void click1(object sender, RoutedEventArgs e) 
     { 
      UserControl1 add = new UserControl1(); 
      Move.Children.Clear(); 
      Move.Children.Add(add); 
     } 

     private void click2(object sender, RoutedEventArgs e) 
     { 
      UserControl2 add = new UserControl2(); 
      Move.Children.Clear(); 
      Move.Children.Add(add); 
     } 
,
+0

당신이 코드를 시도 할 수 있습니다 뒤에 같은 것을 수행 Application.Current.MainWindow.Height = add.Height을; 그리고 메인 윈도우에서 높이를 넣으려고 했습니까? – sexta13

+0

도와 주셔서 감사합니다. 답변을 쓸 수 있습니까? – ITInWorld

답변

0

다음과 같은 코드를 사용해보십시오. Application.Current.MainWindow.Height = add.Height; 그리고 메인 윈도우에서 시도해 보았습니까?

관련,

관련 문제