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

时间:2018-08-28 14:16:21

标签: wpf vb.net menu navigation menubar

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

  

PresentationFramework.dll中发生了'System.InvalidOperationException'类型的未处理异常。其他信息:无法解析属性路径'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响应。我会提前感谢你们,因为我被困在任务中。

1 个答案:

答案 0 :(得分:0)

设置(时缺少) 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>