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

UWP ScrollViewer headers are loaded twice #1367

Closed
nseveno opened this issue Sep 23, 2019 · 4 comments
Closed

UWP ScrollViewer headers are loaded twice #1367

nseveno opened this issue Sep 23, 2019 · 4 comments
Labels
area-Scrolling needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) no-issue-activity

Comments

@nseveno
Copy link

nseveno commented Sep 23, 2019

Hi,

In a UWP application, the controls inside the ScrollViewer’s LeftHeader, TopHeader, TopLeftHeader are loaded twice.

Here is the XAML :

<ScrollViewer Background="LightGray"
                  HorizontalScrollMode="Auto"
                  HorizontalScrollBarVisibility="Auto"
                  VerticalScrollMode="Auto"
                  VerticalScrollBarVisibility="Auto">
        <ScrollViewer.TopHeader>
            <Rectangle x:Name="_topRectangle"
                       Fill="DarkGray"
                       Height="32"
                       Width="10000"
                       Loaded="_topRectangle_Loaded"
                       Unloaded="_topRectangle_Unloaded" />
        </ScrollViewer.TopHeader>
        <ScrollViewer.LeftHeader>
            <Rectangle Fill="DarkGray"
                       Width="32"
                       Height="10000"
                       Loaded="_leftRectangle_Loaded"
                       Unloaded="_leftRectangle_Unloaded"/>
        </ScrollViewer.LeftHeader>
        <ScrollViewer.TopLeftHeader>
            <Rectangle Fill="Gray"
                       Height="32"
                       Width="32"
                       Loaded="_topLeftRectangle_Loaded"
                       Unloaded="_topLeftRectangle_Unloaded" />
        </ScrollViewer.TopLeftHeader>
        <TextBlock x:Name="_textBlock"
                   Loaded="_textBlock_Loaded"
                   Unloaded="_textBlock_Unloaded"
                   Text="Test"
                   Width="10000"
                   Height="10000"
                   FontSize="48"
                   Foreground="Blue"
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top" />
    </ScrollViewer>

And for the C# code, I just call Debug.WriteLine in each Loaded and Unloaded events.

Here is the output :

_textBlock_Loaded

  _leftRectangle_Loaded
  _topRectangle_Loaded
  _topLeftRectangle_Loaded

  _leftRectangle_Loaded
  _topRectangle_Loaded
  _topLeftRectangle_Loaded

  _topLeftRectangle_Unloaded
  _topRectangle_Unloaded
  _leftRectangle_Unloaded

For each control, the events are raised in the following order : Loaded, Loaded, Unloaded. And if I remove the ScrollViewer from the visual tree, the Unloaded event is raised once again.

This causes problems in a real application. I have some user controls inside the headers and they don’t like to be double-loaded. The ScrollViewer headers should be loaded only once.

Also I tried to put a Win2D CanvasVirtualControl in the TopHeader property. It does not work, nothing is rendered. I think it is also linked to this double-loading behavior…

@nseveno
Copy link
Author

nseveno commented Sep 23, 2019

Here is a minimal repro project :

ReproEventsBug.zip

@jevansaks
Copy link
Member

Loaded/Unloaded has been painful for a while but it's difficult to fix in a backwards compatible way. We'll be able to address it more completely in WinUI 3.0+. Since Windows 1809 I think we have support for the "IsLoaded" property. @ddalp do we also have the changed notification for this property, or a writeup of the recommended way to use this property to solve the duplicate notifications issue?

@nseveno
Copy link
Author

nseveno commented Sep 24, 2019

Thanks for the answer.

I can't use the IsLoaded property since I target the 1803 platform.
But a counter incremented in Loaded and decremented in Unloaded does the trick.

I'll wait for the new "flexible" ScrollViewer. It seems to be a lot more customizable...

@jevansaks jevansaks added area-Framework needs-triage Issue needs to be triaged by the area owners labels Nov 7, 2019
@chrisglein chrisglein added area-Scrolling needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) and removed needs-triage Issue needs to be triaged by the area owners labels Jan 24, 2020
@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Scrolling needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) no-issue-activity
Projects
None yet
Development

No branches or pull requests

3 participants