使用情节提要更改WPF中栅格的高度

使用情节提要更改WPF中栅格的高度,wpf,storyboard,Wpf,Storyboard,我正在尝试使用故事板将WPF网格的高度从0更改为Auto。我知道如果不耍花招我是做不到的,所以我尝试在情节提要中使用数据绑定来更改MaxHeight值。但我不能让它工作(高度总是等于0)。以下是我使用的代码: 两种可视状态: <VisualState x:Name="SelectionMode"> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="

我正在尝试使用故事板将WPF网格的高度从
0
更改为
Auto
。我知道如果不耍花招我是做不到的,所以我尝试在情节提要中使用数据绑定来更改MaxHeight值。但我不能让它工作(高度总是等于0)。以下是我使用的代码:

两种可视状态:

 <VisualState x:Name="SelectionMode">
      <Storyboard>
           <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CurrentToolGrid" Storyboard.TargetProperty="(FrameworkElement.MaxHeight)">
                <EasingDoubleKeyFrame KeyTime="0" Value="0" />                  
           </DoubleAnimationUsingKeyFrames> 
       </Storyboard>
 </VisualState>

 <VisualState x:Name="EditionMode">
      <Storyboard>
           <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CurrentToolGrid" Storyboard.TargetProperty="(FrameworkElement.MaxHeight)">
                <EasingDoubleKeyFrame KeyTime="0" Value="{Binding ElementName=CurrentToolGrid, Path=ActualHeight}" />               
           </DoubleAnimationUsingKeyFrames> 
       </Storyboard>
 </VisualState>

以下是我的网格定义:

 <Grid x:Name="CurrentToolGrid" Background="#FFDEDEDE" Grid.Row="1" Height="Auto">
      [... some controls that extends the grid's height ...]
 </Grid>

[…一些扩展栅格高度的控件…]
为什么
CurrentToolGrid
的高度始终为0


感谢您的帮助:)

请参考以下代码,我使用TranslateTransform而不是MaxWidth,它为幻灯片场景制作场景。要实现这一点,请在资源中定义情节提要,然后情节提要可以在doubleanimation中找到绑定的指定控件

<Window x:Class="SlideUpWPFTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        x:Name="Window"
        Title="MainWindow"
        Width="640"
        Height="480">
    <Window.Resources>
        <Storyboard x:Key="sb1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="grdContent" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                <EasingDoubleKeyFrame KeyTime="0" Value="{Binding ElementName=grdContent, Path=ActualWidth}" />
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Key="sb2">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="grdContent" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
                <EasingDoubleKeyFrame KeyTime="0" Value="0" />
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="{Binding ElementName=grdContent, Path=ActualWidth}" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>

    <Grid x:Name="LayoutRoot" RenderTransformOrigin="0.5,0.5">
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.RenderTransform>
            <TransformGroup>
                <ScaleTransform />
                <SkewTransform />
                <RotateTransform />
                <TranslateTransform />
            </TransformGroup>
        </Grid.RenderTransform>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="EditMode" Storyboard="{StaticResource sb1}" />
                <VisualState x:Name="SelectionMode" Storyboard="{StaticResource sb2}" />
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
            <Button Content="Enter Edit Mode">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction StateName="EditMode" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Content="Enter Selected Mode">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction StateName="SelectionMode" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>

        <Grid x:Name="grdContent"
              Grid.Row="1"
              RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform />
                    <SkewTransform />
                    <RotateTransform />
                    <TranslateTransform />
                </TransformGroup>
            </Grid.RenderTransform>
            <!--  some content  -->
            <Rectangle Height="65" Fill="LightBlue" />
        </Grid>
    </Grid>
</Window>


我认为您希望在编辑模式时隐藏ToolGrid,在选择模式时显示ToolGrid,所以为什么不尝试将ToolGrid的可见性属性设置为可见和折叠?因为我希望它向上滑动。