문제

그리드에 2 개의 열이 있습니다. 버튼을 클릭하면 첫 번째 열이 현재 위치에서 0으로 왼쪽으로 애니메이션되기를 원합니다. 따라서 실제로 무너지면 단일 열만 보는 것이 남습니다.

도움이 되었습니까?

해결책

체크 아웃 이것 Todd Miranda의 비디오 교육 링크는 그리드 컨트롤의 높이를 애니메이션하는 방법을 보여줍니다. 나는 당신이 당신의 사건에 쉽게 작동하게 할 수 있다고 생각합니다.

다른 팁

너무 힘들어서는 안됩니다. 그리드를 타겟팅하고 이중 방해물을 사용하여 열 너비를 축소하는 eventtrigger를 만들어야합니다. 여기서 예제에는 비슷한 설정이 있습니다. 이벤트 트리거는 버튼과 DoubleAnimation의 스토리 보드. 표적 축소하려는 칼럼 정의를 가리킬 것입니다.

좋아요, 그렇게 잘 작동하지 않습니다. 열을 직접 축소 할 수는 없지만 수축 열을 채우도록 설정하고 (width = "*") 그리드의 너비와 비 링크 열을 설정 한 다음 전체 그리드를 축소 할 수 있습니다. 이것은 작동합니다. 아래 예제는 작동합니다.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      WindowTitle="Opacity Animation Example" 
      Background="White">
   <StackPanel Margin="20">
      <Grid Name="MyGrid" Width="200" HorizontalAlignment="Left">
         <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="100"/>
         </Grid.ColumnDefinitions>
         <Rectangle HorizontalAlignment="Stretch"  
                    VerticalAlignment="Stretch" 
                    Grid.Column="0" Fill="Red"/>
         <Rectangle HorizontalAlignment="Stretch"  
                    VerticalAlignment="Stretch" 
                    Grid.Column="1" Fill="Blue"/>
      </Grid>

      <Button Name="hideButton">
         <Button.Triggers>
            <EventTrigger RoutedEvent="Button.Click">
               <BeginStoryboard>
                  <Storyboard>
                     <DoubleAnimation 
                         Storyboard.TargetName="MyGrid"
                         Storyboard.TargetProperty="(Grid.Width)" 
                         From="200" To="100" 
                         Duration="0:0:2" 
                         AutoReverse="True"  /> 
                  </Storyboard>
               </BeginStoryboard>
            </EventTrigger>
         </Button.Triggers>
      </Button>
   </StackPanel>
</Page>

gridlengthanimation 클래스를 만들어야합니다 (코드에서 : http://windowsclient.net/learn/video.aspx?v=70654)

public class GridLengthAnimation : AnimationTimeline
{
    public GridLengthAnimation()
    {
        // no-op
    }

    public GridLength From
    {
        get { return (GridLength)GetValue(FromProperty); }
        set { SetValue(FromProperty, value); }
    }

    public static readonly DependencyProperty FromProperty =
      DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation));

    public GridLength To
    {
        get { return (GridLength)GetValue(ToProperty); }
        set { SetValue(ToProperty, value); }
    }

    public static readonly DependencyProperty ToProperty =
        DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation));

    public override Type TargetPropertyType
    {
        get { return typeof(GridLength); }
    }

    protected override Freezable CreateInstanceCore()
    {
        return new GridLengthAnimation();
    }

    public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock)
    {
        double fromValue = this.From.Value;
        double toValue = this.To.Value;

        if (fromValue > toValue)
        {
            return new GridLength((1 - animationClock.CurrentProgress.Value) * (fromValue - toValue) + toValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
        }
        else
        {
            return new GridLength((animationClock.CurrentProgress.Value) * (toValue - fromValue) + fromValue, this.To.IsStar ? GridUnitType.Star : GridUnitType.Pixel);
        }
    }
}

그리고 RowDefinition/ColumnDefinition의 스토리 보드.

<Window.Resources>
    <Storyboard x:Key="ColumnAnimation">
        <Animations:GridLengthAnimation
            BeginTime="0:0:0"
            Duration="0:0:0.1"
            From="0*"
            Storyboard.TargetName="ColumnToAnimate"
            Storyboard.TargetProperty="Width"
            To="10*" />
    </Storyboard>

</Window.Resources>

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="10*" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition x:Name="ColumnToAnimate" Width="0*" />
    </Grid.ColumnDefinitions>
</Grid>

당신이 할 수있는 또 다른 일은 내용을 애니메이션하고 그리드를 컨텐츠로 설정하여 컨텐츠 크기가 변경 될 때 부드럽게 수행되는 컨텐츠로 설정하는 것입니다.

Kevin 's Bag-O-Tricks의 공개 컨트롤을 사용할 수도 있습니다. http://j832.com/bagotricks/

Gridlength Animation으로이를 달성 할 수 있습니다. 여기 예를 참조하십시오. http://marlongrech.wordpress.com/2007/08/20/gridlength-animation/ 이 접근법을 사용하면 주어진 Grid.column 또는 Grid.row 크기를 조작 할 수 있습니다.

특별한 필요에 대해서는 너비 = "자동"이있는 첫 번째 열을, 두 번째 열을 *와 함께, 첫 번째 열 내부의 내용을 애니메이션하십시오.

Datagrid 열 폭이 줄어들고 확장되는 방법을 보여주기 위해 Todd Miranda의 C# 소스 코드를 가져 와서 수정했습니다.

소스 코드는 다음과 같습니다 ...

http://www.pocketpctoolkit.com/wpf/datagridcolumnwidthanimation.zip

기본적으로 확인란을 클릭하면 DataGrid 열에 "minwidth"값이 0으로 설정된 사람이있는 것 중 어느 것도 0을 제한으로 줄어 듭니다. 확인란을 다시 클릭하면 열이 원래 너비로 다시 애니메이션됩니다.

이 WPF 코드는 또한 코드 뒤에 애니메이션 / 스토리 보드를 만드는 방법을 보여줍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top