Панель навигации с использованием ошибки WPF (невозможно разрешить все ссылки на свойства в пути к свойствам) - PullRequest
0 голосов
/ 28 августа 2018

Я работал над разработкой форм для Windows и новой разработкой для WPF. я понятия не имею о разработке Xaml. я написал код, но столкнулся с ошибкой

Произошло необработанное исключение типа «System.InvalidOperationException» в PresentationFramework.dll. Дополнительная информация: Не удается разрешить все ссылки на свойства в пути к свойству «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 голосов
/ 28 августа 2018

Вы пропускаете ( ) при настройке Storyboard.TargetProperty.

Подробнее о пути к собственности можно узнать здесь .

Просто измените раскадровку на:

<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>
...