导航栏使用 WPF 错误(无法解析 属性 路径中的所有 属性 引用)

Navigation Bar Using WPF error (Cannot resolve all property references in the property path)

我曾从事 Windows 表单开发和 WPF 开发的新工作。我对 Xaml 开发一无所知。我写了一些代码但遇到错误

An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll Additional information: Cannot resolve all property references in the property path 'FrameworkElement.Width'.

下面是我的 Xaml 代码。

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="600" Width="1080" ResizeMode="NoResize" WindowStyle="None" Foreground="White"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" >
    <Window.Resources>
        <Storyboard x:Key="MenuOpen">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="FrameworkElement.Width" Storyboard.TargetName="GridMenu">
                <EasingDoubleKeyFrame KeyTime="0" Value="60"></EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="200"></EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="MenuClose">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="FrameworkElement.Width" Storyboard.TargetName="GridMenu">
                <EasingDoubleKeyFrame KeyTime="0" Value="200"></EasingDoubleKeyFrame>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="60"></EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonOpenMenu">
            <BeginStoryboard Storyboard="{StaticResource MenuOpen}"></BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonCloseMenu">
            <BeginStoryboard Storyboard="{StaticResource MenuClose}"></BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
    <Grid Background="LightGray">
        <Grid Height="60" VerticalAlignment="Top" Background="#FF1368BD">
            <TextBlock Text="Tuck Shop Management System" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22"></TextBlock>
            <StackPanel VerticalAlignment="Center" Orientation="Horizontal" HorizontalAlignment="Right"> 
                <TextBlock Text="User Profile" VerticalAlignment="Center" FontSize="18"></TextBlock>
                <materialDesign:PopupBox Margin="10" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
                    <StackPanel Width="150">
                        <Button Content="Account"></Button>
                        <Button Content="Setting"></Button>
                        <Button Content="Help"></Button>
                        <Separator></Separator>
                        <Button x:Name="ButtonPopoutLogout" Content="Logout" Click="ButtonPopoutLogout_Click"></Button>
                    </StackPanel>
                </materialDesign:PopupBox>
            </StackPanel> 
        </Grid>
        <Grid x:Name="GridMenu" Width="60" HorizontalAlignment="Left" Background="#FF1A3761"> 
            <StackPanel>  
                <Grid Height="150" Background="White"> 
                    <Button x:Name="ButtonCloseMenu" VerticalAlignment="Top" HorizontalAlignment="Right" Width="60" Height="60" Background="{x:Null}" BorderBrush="{x:Null}" Click="ButtonCloseMenu_Click">
                        <materialDesign:PackIcon Kind="ArrowLeft" Foreground="#FF1A3761" Width="25" Height="25" Visibility="Collapsed"></materialDesign:PackIcon>
                    </Button>
                    <Button x:Name="ButtonOpenMenu" VerticalAlignment="Top" HorizontalAlignment="Right" Width="60" Height="60" Background="{x:Null}" BorderBrush="{x:Null}" Click="ButtonOpenMenu_Click">
                        <materialDesign:PackIcon Kind="Menu" Foreground="#FF1A3761" Width="25" Height="25"></materialDesign:PackIcon> 
                    </Button>
                </Grid>
                <ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled" Foreground="#FF1368BD" MouseDown="ListView_MouseDown">
                    <ListViewItem Height="60" x:Name="Home">  
                        <StackPanel Orientation="Horizontal">
                            <materialDesign:PackIcon Kind="ViewDashboard" Height="25" Width="25" Margin="10" VerticalAlignment="Center"></materialDesign:PackIcon>
                            <TextBlock Text="Home" VerticalAlignment="Center" Margin="20 10"></TextBlock>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="60">
                        <StackPanel Orientation="Horizontal">
                            <materialDesign:PackIcon Kind="Pencil" Height="25" Width="25" Margin="10" VerticalAlignment="Center"></materialDesign:PackIcon>
                            <TextBlock Text="Create" VerticalAlignment="Center" Margin="20 10"></TextBlock>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="60">
                        <StackPanel Orientation="Horizontal">
                            <materialDesign:PackIcon Kind="Ticket" Height="25" Width="25" Margin="10" VerticalAlignment="Center"></materialDesign:PackIcon>
                            <TextBlock Text="Ticket" VerticalAlignment="Center" Margin="20 10"></TextBlock>
                        </StackPanel>
                    </ListViewItem>
                    <ListViewItem Height="60">
                        <StackPanel Orientation="Horizontal">
                            <materialDesign:PackIcon Kind="Message" Height="25" Width="25" Margin="10" VerticalAlignment="Center"></materialDesign:PackIcon>
                            <TextBlock Text="Message" VerticalAlignment="Center" Margin="20 10"></TextBlock>


        </StackPanel>
                </ListViewItem>
                <ListViewItem Height="60">
                    <StackPanel Orientation="Horizontal">
                        <materialDesign:PackIcon Kind="GithubBox" Height="25" Width="25" Margin="10" VerticalAlignment="Center"></materialDesign:PackIcon>
                        <TextBlock Text="Git Hub" VerticalAlignment="Center" Margin="20 10"></TextBlock>
                    </StackPanel>
                </ListViewItem>
            </ListView>
        </StackPanel>
    </Grid>
</Grid>

我还有下面给出的代码。

Private Sub ButtonPopoutLogout_Click(sender As Object, e As RoutedEventArgs)
    Application.Current.Shutdown()
End Sub

Private Sub ButtonOpenMenu_Click(sender As Object, e As RoutedEventArgs)
    ButtonOpenMenu.Visibility = Windows.Visibility.Collapsed
    ButtonCloseMenu.Visibility = Windows.Visibility.Visible
End Sub

Private Sub ButtonCloseMenu_Click(sender As Object, e As RoutedEventArgs)
    ButtonOpenMenu.Visibility = Windows.Visibility.Visible
    ButtonCloseMenu.Visibility = Windows.Visibility.Collapsed
End Sub

等待 +ve 响应。我会提前感谢你们,因为我被困在任务中。

您在设置 Storyboard.TargetProperty 时缺少 ( )

您可以找到更多关于 属性 路径 here

只需将故事板更改为:

<Storyboard x:Key="MenuOpen">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
        <EasingDoubleKeyFrame KeyTime="0" Value="60"></EasingDoubleKeyFrame>
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="200"></EasingDoubleKeyFrame>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="MenuClose">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
        <EasingDoubleKeyFrame KeyTime="0" Value="200"></EasingDoubleKeyFrame>
        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="60"></EasingDoubleKeyFrame>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>