2011-03-03 2 views
0

알아낼 수없는 문제가 있습니다. 나는 충분히 설명 할 수 있기를 바란다.WPF - Usercontrol 높이의 크기가 적절하지 않습니다.

기본적으로 나는 윈도우 모달 대화 상자의 일종으로 사용하려고하는 usercontrol이 있습니다.

<Grid> 
    <Rectangle Opacity=".75" Fill="White"/> 
    <Border Width="425" BorderBrush="LightGray" BorderThickness="2" CornerRadius="20,0,20,0" Padding="3"> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="auto"/> 
       <ColumnDefinition Width="*"/> 
       <ColumnDefinition Width="auto"/> 
       <ColumnDefinition Width="*"/> 
       <ColumnDefinition Width="auto"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="auto"/> 
       <RowDefinition Height="auto"/> 
       <RowDefinition Height="auto"/> 
       <RowDefinition Height="15"/> 
       <RowDefinition Height="auto"/> 
      </Grid.RowDefinitions> 
      <!-- First Name --> 
      <Label Grid.Row="0" Grid.Column="0" Content="First Name:"/> 
      <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Text="{Binding FirstName}" Margin="3"/> 
      <!-- Last Name --> 
      <Label Grid.Row="0" Grid.Column="3" Content="Last Name:"/> 
      <TextBox Grid.Row="0" Grid.Column="4" Grid.ColumnSpan="2" Text="{Binding LastName}" Margin="3"/> 
      <!-- Address --> 
      <Label Grid.Row="1" Grid.Column="0" Content="Address:"/> 
      <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="5" Text="{Binding Address}" HorizontalAlignment="Stretch" Margin="3"/> 
      <!-- City --> 
      <Label Grid.Row="2" Grid.Column="0" Content="City:"/> 
      <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding City}" Margin="3"/> 
      <!-- State --> 
      <Label Grid.Row="2" Grid.Column="2" Content="State:"/> 
      <ComboBox Grid.Row="2" Grid.Column="3" ItemsSource="{Binding States}" SelectedValue="{Binding State}" Margin="3"/> 
      <!-- Zip Code --> 
      <Label Grid.Row="2" Grid.Column="4" Content="Zip Code:"/> 
      <TextBox Grid.Row="2" Grid.Column="5" Text="{Binding ZipCode}" Margin="3"/> 
      <Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="6" Width="100" HorizontalAlignment="Center" Content="Save" Command="{Binding SaveCustomerCommand}"/> 
     </Grid> 
    </Border> 
</Grid> 

또한이 usercontrol을 viewmodel에 연결하는 datatemplate을 포함하는 resourcedictionary가 있습니다.

<DataTemplate DataType="{x:Type vm:CreateCustomerViewModel}"> 
    <view:CreateCustomerView/> 
</DataTemplate> 

마지막으로, 기본 창 뷰 모델에서, 나는 컨트롤의 뷰 모델의 인스턴스를 생성하고 메인 창보기에, 나는 ItemsControl에를 사용하고 컨트롤의 뷰 모델의 인스턴스에 itemssource 숙박 시설의 결합입니다. 이제 내 문제는 메인 윈도우의 ItemsControl을 사용하고

 <ItemsControl Height="600" Grid.Row="0" ItemsSource="{Binding CreateCustomerViewModel}" Grid.RowSpan="2" /> 

, 나는 몇 가지 방법을 시도했습니다,하지만 난 컨트롤이 윈도우의 높이로 얻을 수 없습니다. itemscontrol을 사용해서는 안되는 지, 아니면 내가 잘못하고있는 것인지 잘 모르겠습니다. 어떤 도움이라도 대단히 감사합니다.

답변

0

ItemsControl은 컬렉션 용입니다. 기본적으로 StackPanel을 사용하여 자식 요소를 포함하므로 스택 방향으로의 확장 (기본적으로 수직)이 허용되지 않습니다. 단일 항목 대신 ContentControl을 (버튼 및 라벨 같은 것들의 기초를) 사용

<ContentControl Height="600" Grid.Row="0" Content="{Binding CreateCustomerViewModel}" Grid.RowSpan="2" /> 
+0

매우 도움이됩니다, 감사합니다! – GenericUsername3043

1

은 다음을 시도해 볼 수도 있습니다 :

ItemsControlGrid A의 넣습니다.

ItemsControlVerticalContentAlignment="Stretch"으로 설정하십시오.

기본 설정이므로 아무런 차이가 없어야하지만, ItemsControlVerticalAlignment="Stretch"으로 선언하고 Height="600"을 제거해보세요.

+0

불행하게도, 둘 다 트릭을 할 것 없습니다. 최종 결과는 같습니다. 컨트롤은 너비에 맞게 잘 확장되지만 높이는 컨트롤의 높이에 머물러 있습니다. 컨트롤이 실제로 창 중간에오고, 사각형이 전체 창을 차지할 때입니다. – GenericUsername3043