2010-01-10 2 views
0

WPF에서 Outlook 추가 기능을 개발 중입니다. Outlook 추가 기능은 UserControl입니다. 내 단순화 된 XAML 코드 모양 :wpf에서 그리드 행의 높이를 제한하는 방법

<UserControl> 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="150"/> 
       <RowDefinition Height="*"/> 
       <RowDefinition Height="20"/> 
      </Grid.RowDefinitions> 
      <TextBlock Grid.Row="0">Header</TextBlock> 
      <ListBox Grid.Row="1"></ListBox> 
      <Button Grid.Row="2"></Button> 
     </Grid> 
    </UserControl> 

목록 상자 항목은 동적으로로드됩니다. 여기에 설립 한이 수업의 도움으로 http://www.codeproject.com/KB/WPF/GridLengthAnimation.aspx 버튼을 누를 때 세 번째 행의 높이가 0.4 *로 설정됩니다.

문제는 두 번째 행이 확장되고 세 번째 행이 사라진다는 것입니다. 두 번째 행의 MaxHeight을 100 % 높이 170으로 설정하면 해결책이 될 수 있지만 UserControl의 사용 가능한 높이를 알지 못합니다.

아이디어가 있으십니까?

답변

0

문제는 내가 GridUnitType.Pixel으로 GridUnitType.Star을 대체 한

public override object GetCurrentValue(object defaultOriginValue, 
     object defaultDestinationValue, AnimationClock animationClock) 
    { 
     double fromVal = ((GridLength)GetValue(GridLengthAnimation.FromProperty)).Value; 
     double toVal = ((GridLength)GetValue(GridLengthAnimation.ToProperty)).Value; 

     if (fromVal > toVal) 
     { 
      return new GridLength((1 - animationClock.CurrentProgress.Value) * (fromVal - toVal) + toVal, GridUnitType.Pixel); 
     } 
     else 
      return new GridLength(animationClock.CurrentProgress.Value * (toVal - fromVal) + fromVal, GridUnitType.Pixel); 
    } 

(내가 사용했던 그 도서관에) 여기에 있었다. 이제는 완벽하게 작동합니다.

0

Height을 지정하는 대신 3 번째 행에 MinHeight을 지정하면 특정 크기 이상으로 축소되지 않습니다.

관련 문제