Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NavigationView pane not closed by default when using IsPaneOpen="False" #1012

Merged
merged 1 commit into from
Mar 22, 2024
Merged

Conversation

tmijail
Copy link
Contributor

@tmijail tmijail commented Mar 21, 2024

Pull request type

Please check the type of change your PR introduces:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

Setting IsPaneOpen="False" on a NavigationView is ignored.

Issue Number: #741

What is the new behavior?

When IsPaneOpen="False", the pane starts collapsed.

Other information

Call VisualStateManager.GoToState once the control has loaded

Closes #741
@tmijail tmijail requested a review from pomianowski as a code owner March 21, 2024 18:53
@github-actions github-actions bot added controls Changes to the appearance or logic of custom controls. PR Pull request navigation Changes to navigation related controls. dotnet labels Mar 21, 2024
@pomianowski pomianowski self-assigned this Mar 22, 2024
@pomianowski pomianowski merged commit 4320b02 into lepoco:development Mar 22, 2024
2 checks passed
@pomianowski pomianowski linked an issue Mar 22, 2024 that may be closed by this pull request
@koal44
Copy link
Contributor

koal44 commented Mar 23, 2024

There's a bug:

System.Windows.Media.Animation.AnimationException:
'Cannot animate the 'Width' property on a 'System.Windows.Controls.Grid' using a 'System.Windows.Media.Animation.DoubleAnimation'.
InvalidOperationException:
'System.Windows.Media.Animation.DoubleAnimation' cannot use default destination value of 'NaN'.

To reproduce, open the Gallery App and head over to the Navigations Page.

The problem was introduced when you ran UpdateVisualState method for every NavigationView control when it's loaded, although i think the problem is a bit more tricky.

I'll try to help narrow down what's going on.

In the GalleryApp, NavigationViewPage.xaml, we use a <ui:NavigationView PaneDisplayMode="LeftFluent"/>.
In Wpf.Ui, styling for NavigationView.xaml we have

<Style.Triggers>
    <Trigger Property="PaneDisplayMode" Value="Left">
        <Setter Property="ItemTemplate" Value="{StaticResource LeftCompactNavigationViewItemTemplate}" />
    </Trigger>
    <Trigger Property="PaneDisplayMode" Value="LeftFluent">
        <Setter Property="OpenPaneLength" Value="NaN" />
    </Trigger>
</Style.Triggers>

and in NavigationViewCompact.xaml (LeftCompactNavigationViewItemTemplate), we have animations that run visual state changes <DoubleAnimation To="{TemplateBinding OpenPaneLength}" />

Even though the template for Left doesn't apply for LeftFluent the TemplateBinding will update to NaN and cause problems.

tmijail added a commit to tmijail/wpfui that referenced this pull request Mar 24, 2024
As @koal44 pointed out, lepoco#1012 introduced a bug which made the app crash when using FluentLeft navigation because updating the visual state tries to animate a width to or from OpenPaneLength=NaN.

To avoid this, don't try to change the visual state for navigation view modes that don't have an open and a compact state.
@tmijail tmijail mentioned this pull request Mar 24, 2024
7 tasks
@tmijail
Copy link
Contributor Author

tmijail commented Mar 24, 2024

@koal44 You're right. I didn't check the other display modes. Really sorry about that.

I sent a fix in PR #1015.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controls Changes to the appearance or logic of custom controls. dotnet navigation Changes to navigation related controls. PR Pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pane is not closed by default when using IsPaneOpen="False"
3 participants