WPF动画找不到依赖属性:属性未指向路径“(0).(1)[3].(2)”中的 DependencyObject

这是代码:

<Window x:Class="Ani.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Ani"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        mc:Ignorable="d" Height="600" Width="1080" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None">
    <Window.Resources>
        <Storyboard x:Key="CloseMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="GridMenu">
                <EasingDoubleKeyFrame KeyTime="0" Value="250"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="GridBackground">
                <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OpenMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="GridMenu">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="250"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="GridBackground">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonClose">
            <BeginStoryboard x:Name="CLoseMenu_BeginStoryBoard" Storyboard="{DynamicResource CloseMenu}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonOpen">
            <BeginStoryboard Storyboard="{DynamicResource OpenMenu}"/>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
        <Grid x:Name="GridBackground" Background="#55313131" Opacity="0">
            <Grid.RenderTransform>
                <TransformGroup>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </TransformGroup>
            </Grid.RenderTransform>
        </Grid>
        <Button Name="ButtonOpen" Background="Transparent" BorderBrush="Transparent" Click="ButtonClose_Click" Width="40" Height="40" Margin="0,0,1040,560" >
            <materialDesign:PackIcon Kind="Menu" Height="25" Width="28" Foreground="Gray"  Padding="0"/>
        </Button>
        <Grid x:Name="GridMenu" Width="250"  HorizontalAlignment="Left" Margin="-250,0,0,0" Background="White" RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </TransformGroup>
            </Grid.RenderTransform>
            <StackPanel>
                <Image Height="140" Stretch="Fill">
                    <Image.Source>
                        <BitmapImage UriSource="file:///C:/Users/Jeremy/Desktop/yuanjian/Practice/Pic/timg.jpg"/>
                    </Image.Source>
                </Image>
                <ListView Foreground="#FF313131" FontFamily="Chamoagne &amp; Limousines" FontSize="18" BorderBrush="Transparent">
                    <ListViewItem Height="45" Padding="0">
                        <StackPanel Orientation="Horizontal" Margin="10 0">
                            <materialDesign:PackIcon Kind="Recycle" Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="Gray"/>
                            <TextBlock Text="Recycle" Margin="10"/>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="45" Padding="0">
                        <StackPanel Orientation="Horizontal" Margin="10 0">
                            <materialDesign:PackIcon Kind="HelpCircleOutline"  Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="#FFF08033"/>
                            <TextBlock Text="Help" Margin="10"/>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="45" Padding="0">
                        <StackPanel Orientation="Horizontal" Margin="10 0">
                            <materialDesign:PackIcon Kind="Lightbulb" Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="Green"/>
                            <TextBlock Text="Send Feedback" Margin="10"/>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="45" Padding="0">
                        <StackPanel Orientation="Horizontal" Margin="10 0">
                            <materialDesign:PackIcon Kind="Heart" Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="#FFD41515"/>
                            <TextBlock Text="Recommend" Margin="10"/>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="45" Padding="0">
                        <StackPanel Orientation="Horizontal" Margin="10 0">
                            <materialDesign:PackIcon Kind="StarCircle" Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="#FFE6A701"/>
                            <TextBlock Text="Premiun Subscription" Margin="10"/>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="45" Padding="0">
                        <StackPanel Orientation="Horizontal" Margin="10 0">
                            <materialDesign:PackIcon Kind="Settings" Width="20" Height="20" VerticalAlignment="Center" Margin="5" Foreground="#FF0069C1"/>
                            <TextBlock Text="Settings" Margin="10"/>
                        </StackPanel>
                    </ListViewItem>


                </ListView>
            </StackPanel>
            <Button Name="ButtonClose" Margin="216,0,0,571" Background="Transparent" BorderBrush="Transparent" Height="40" Width="40" Click="ButtonClose_Click"  >
                <materialDesign:PackIcon Kind="Close" Height="25" Width="28" Foreground="White"  Padding="0"/>
            </Button>
        </Grid>
    </Grid>
</Window>

为什么我在Grid里写了TransformGroup,运行时还是出错了?

图片说明
这是写界面时的样子

报错图片说明

大神帮帮看看哪里出了问题~

c#

1个回答

<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="GridMenu"
改为
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)" Storyboard.TargetName="GridMenu"

你的引用元素 的TransformGroup.Children 就自己有一个变换

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!