AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.19k stars 2.27k forks source link

Routing to old pages get blank content using RoutedViewHost #9387

Closed laolarou726 closed 1 year ago

laolarou726 commented 2 years ago

Describe the bug 🐞

When trying to navigate to a page that was previously loaded, RoutedViewHost will become a blank page.

Step to reproduce

  1. Go to the next page
  2. Then go to a page that was loaded
  3. See a blank page
  4. If click next and then navigate to that page again, the page will show up again

Reproduction repository

No response

Expected behavior

When navigate to a previous page, the view should show up normally

Screenshots 🖼️

动画

IDE

Visual Studio 2022

Operating system

Windows

Version

11, 22621.755

AvaloniaUI Version

Avalonia 11.0 - Preview3

ReactiveUI Version

18.3.1

Additional information ℹ️

No response

laolarou726 commented 2 years ago

I found that once I change the template of TransitioningContentControl, everything will be fine. Is that a bug?

Changes I did:


<Style Selector="TransitioningContentControl">
        <Setter Property="Template">
            <ControlTemplate>
                <ContentPresenter Background="{TemplateBinding Background}"
                                  BorderBrush="{TemplateBinding BorderBrush}"
                                  BorderThickness="{TemplateBinding BorderThickness}"
                                  CornerRadius="{TemplateBinding CornerRadius}"
                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                  Content="{TemplateBinding Content}" /* Original should be binding to CurrentContent */
                                  Padding="{TemplateBinding Padding}"
                                  VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                  HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
            </ControlTemplate>
        </Setter>
</Style>
laolarou726 commented 2 years ago

Also, if I set the Content to be {TemplateBinding CurrentContent}. When I navigating to some pages, the exception will throw:


    Avalonia.Base.dll!Avalonia.Media.FontFamily.FontFamily(System.Uri baseUri, string name) 
    Avalonia.Skia.dll!Avalonia.Skia.FontManagerImpl.TryMatchCharacter(int codepoint, Avalonia.Media.FontStyle fontStyle, Avalonia.Media.FontWeight fontWeight, Avalonia.Media.FontStretch fontStretch, Avalonia.Media.FontFamily fontFamily, System.Globalization.CultureInfo culture, out Avalonia.Media.Typeface fontKey) 
    Avalonia.Base.dll!Avalonia.Media.FontManager.TryMatchCharacter(int codepoint, Avalonia.Media.FontStyle fontStyle, Avalonia.Media.FontWeight fontWeight, Avalonia.Media.FontStretch fontStretch, Avalonia.Media.FontFamily fontFamily, System.Globalization.CultureInfo culture, out Avalonia.Media.Typeface typeface)   
    Avalonia.Base.dll!Avalonia.Media.TextFormatting.TextCharacters.CreateShapeableRun(Avalonia.Utilities.ReadOnlySlice<char> text, Avalonia.Media.TextFormatting.TextRunProperties defaultProperties, sbyte biDiLevel, ref Avalonia.Media.TextFormatting.TextRunProperties previousProperties)  
    Avalonia.Base.dll!Avalonia.Media.TextFormatting.TextCharacters.GetShapeableCharacters(Avalonia.Utilities.ReadOnlySlice<char> runText, sbyte biDiLevel, ref Avalonia.Media.TextFormatting.TextRunProperties previousProperties)  
    Avalonia.Base.dll!Avalonia.Media.TextFormatting.TextFormatterImpl.CoalesceLevels(System.Collections.Generic.IReadOnlyList<Avalonia.Media.TextFormatting.TextRun> textCharacters, Avalonia.Utilities.ArraySlice<sbyte> levels)   
    Avalonia.Base.dll!Avalonia.Media.TextFormatting.TextFormatterImpl.ShapeTextRuns(System.Collections.Generic.List<Avalonia.Media.TextFormatting.TextRun> textRuns, Avalonia.Media.TextFormatting.TextParagraphProperties paragraphProperties, out Avalonia.Media.FlowDirection resolvedFlowDirection) 
    Avalonia.Base.dll!Avalonia.Media.TextFormatting.TextFormatterImpl.FormatLine(Avalonia.Media.TextFormatting.ITextSource textSource, int firstTextSourceIndex, double paragraphWidth, Avalonia.Media.TextFormatting.TextParagraphProperties paragraphProperties, Avalonia.Media.TextFormatting.TextLineBreak previousLineBreak)   
    Avalonia.Base.dll!Avalonia.Media.TextFormatting.TextLayout.CreateTextLines()    
    Avalonia.Controls.dll!Avalonia.Controls.TextBlock.CreateTextLayout(string text) 
    Avalonia.Controls.dll!Avalonia.Controls.TextBlock.Render(Avalonia.Media.DrawingContext context) 
    Avalonia.Base.dll!Avalonia.Rendering.Composition.CompositingRenderer.UpdateCore()   
    Avalonia.Base.dll!Avalonia.Rendering.Composition.CompositingRenderer.Update(System.Threading.Tasks.Task batchCompletion)    
    Avalonia.Base.dll!Avalonia.Rendering.Composition.Compositor.Commit()    
    Avalonia.Base.dll!Avalonia.Rendering.Composition.CompositingRenderer.Dispose()  
    Avalonia.Controls.dll!Avalonia.Controls.TopLevel.HandleClosed() 
    Avalonia.Controls.dll!Avalonia.Controls.WindowBase.HandleClosed()   
    Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.AppWndProc(System.IntPtr hWnd, uint msg, System.IntPtr wParam, System.IntPtr lParam)   
    Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.WndProc(System.IntPtr hWnd, uint msg, System.IntPtr wParam, System.IntPtr lParam)  
    [本机到托管的转换]  
    [托管到本机的转换]  
    Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.Dispose()  
    Avalonia.Controls.dll!Avalonia.Controls.Primitives.PopupRoot.Dispose()  
    System.Reactive.dll!System.Reactive.Disposables.AnonymousDisposable<(Avalonia.Controls.Primitives.IPopupHost, System.Reactive.Disposables.CompositeDisposable)>.Dispose()   
    Avalonia.Controls.dll!Avalonia.Controls.Primitives.Popup.CloseCore()    
    Avalonia.Controls.dll!Avalonia.Controls.ComboBox.OnPointerReleased(Avalonia.Input.PointerReleasedEventArgs e)   
    System.Reactive.dll!System.Reactive.Subjects.Subject<(object, Avalonia.Interactivity.RoutedEventArgs)>.OnNext((object, Avalonia.Interactivity.RoutedEventArgs) value)   
    Avalonia.Base.dll!Avalonia.Interactivity.EventRoute.RaiseEventImpl(Avalonia.Interactivity.RoutedEventArgs e)    
    Avalonia.Base.dll!Avalonia.Interactivity.EventRoute.RaiseEvent(Avalonia.Interactivity.IInteractive source, Avalonia.Interactivity.RoutedEventArgs e)    
    Avalonia.Base.dll!Avalonia.Interactivity.Interactive.RaiseEvent(Avalonia.Interactivity.RoutedEventArgs e)   
    Avalonia.Base.dll!Avalonia.Input.MouseDevice.MouseUp(Avalonia.Input.IMouseDevice device, ulong timestamp, Avalonia.Input.IInputRoot root, Avalonia.Point p, Avalonia.Input.PointerPointProperties props, Avalonia.Input.KeyModifiers inputModifiers, Avalonia.Input.IInputElement hitTest)  
    Avalonia.Base.dll!Avalonia.Input.MouseDevice.ProcessRawEvent(Avalonia.Input.Raw.RawPointerEventArgs e)  
    Avalonia.Base.dll!Avalonia.Input.InputManager.ProcessInput(Avalonia.Input.Raw.RawInputEventArgs e)  
    Avalonia.Controls.dll!Avalonia.Controls.TopLevel.HandleInput(Avalonia.Input.Raw.RawInputEventArgs e)    
    Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.AppWndProc(System.IntPtr hWnd, uint msg, System.IntPtr wParam, System.IntPtr lParam)   
    Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.WndProc(System.IntPtr hWnd, uint msg, System.IntPtr wParam, System.IntPtr lParam)  
    [本机到托管的转换]  
    [托管到本机的转换]  
    Avalonia.Win32.dll!Avalonia.Win32.Win32Platform.RunLoop(System.Threading.CancellationToken cancellationToken)   
    Avalonia.Base.dll!Avalonia.Threading.Dispatcher.MainLoop(System.Threading.CancellationToken cancellationToken)  
    Avalonia.Controls.dll!Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(string[] args)    
>   LauncherX.Avalonia.dll!LauncherX.Avalonia.Program.Main(string[] args) Line 15   C#
timunie commented 2 years ago

Hi @laolarou726

your stack trace seems to be missing some important lines at the top. can you please double-check this? Also it might be helpful if you can share a sample App which shows your issue. So we can better debug it.

Happy coding Tim

laolarou726 commented 2 years ago

@timunie hmmm, I'm pretty sure this is the top of the stacktrace:

image image
laolarou726 commented 2 years ago

I'll try to make a sample APP tomorrow. But I'm not sure if it is possible because I don't know what's happened. Sorry about that.

timunie commented 2 years ago

can you inspect what name is? The issue tells us it is null or empty. I think probably you are using a custom font which is causing the issue. @Gillibald may know more about it.

laolarou726 commented 2 years ago

@timunie I failed to create a repro for this issue. I'm using a style to override the FontFamily for most of the controls:

image
laolarou726 commented 2 years ago

@timunie @Gillibald I just created a repo to show the exception: https://github.com/laolarou726/FontExceptionTest

See the Readme file, if you uncomment the code in MDLIconStyle.axaml, the exception will appear.

laolarou726 commented 2 years ago

I found that once I change the template of TransitioningContentControl, everything will be fine. Is that a bug?

Changes I did:


<Style Selector="TransitioningContentControl">

        <Setter Property="Template">

            <ControlTemplate>

                <ContentPresenter Background="{TemplateBinding Background}"

                                  BorderBrush="{TemplateBinding BorderBrush}"

                                  BorderThickness="{TemplateBinding BorderThickness}"

                                  CornerRadius="{TemplateBinding CornerRadius}"

                                  ContentTemplate="{TemplateBinding ContentTemplate}"

                                  Content="{TemplateBinding Content}" /* Original should be binding to CurrentContent */

                                  Padding="{TemplateBinding Padding}"

                                  VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"

                                  HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />

            </ControlTemplate>

        </Setter>

</Style>

@timunie Is that a possible bug for the AvaloniaUI or ReactiveUI? I'm keep getting blank pages if I set the TemplateBinding to "CurrentCotent".

laolarou726 commented 2 years ago

I found that once I change the template of TransitioningContentControl, everything will be fine. Is that a bug? Changes I did:

<Style Selector="TransitioningContentControl">

        <Setter Property="Template">

            <ControlTemplate>

                <ContentPresenter Background="{TemplateBinding Background}"

                                  BorderBrush="{TemplateBinding BorderBrush}"

                                  BorderThickness="{TemplateBinding BorderThickness}"

                                  CornerRadius="{TemplateBinding CornerRadius}"

                                  ContentTemplate="{TemplateBinding ContentTemplate}"

                                  Content="{TemplateBinding Content}" /* Original should be binding to CurrentContent */

                                  Padding="{TemplateBinding Padding}"

                                  VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"

                                  HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />

            </ControlTemplate>

        </Setter>

</Style>

@timunie Is that a possible bug for the AvaloniaUI or ReactiveUI? I keep getting blank pages if I set the TemplateBinding to "CurrentCotent".

@timunie I noticed that the content has been successfully set after the navigation (as you can see in the Logical Tree). However, the real view failed to show those elements up. What I got is a completely empty page.

image image
laolarou726 commented 2 years ago

Once I change the style binding to "Content" instead of "CurrentContent". Everything will be fine except for the page transitions.

laolarou726 commented 2 years ago

Once I change the style binding to "Content" instead of "CurrentContent". Everything will be fine except for the page transitions.

It seems all the sub-elements loss their styles after the navigation is finished.

image image
timunie commented 2 years ago

@kekekeks can this issue be related to the new renderer? If so, you may want to check the transitioning content control while sorting out the renderer bugs present.

laolarou726 commented 2 years ago

@kekekeks can this issue be related to the new renderer? If so, you may want to check the transitioning content control while sorting out the renderer bugs present.

Which part of the transitioning content control I need to look at? The styling or the source?

emmauss commented 2 years ago

Could you create a small repro for the navigating issue?

laolarou726 commented 2 years ago

Could you create a small repro for the navigating issue?

I'll try to create a small repro for this issue. But I don't know if it is possible, because I don't know why this happens. I tried the official demo on the Avalonia's website, everything is fine.

laolarou726 commented 2 years ago

Could you create a small repro for the navigating issue?

@emmauss @timunie I successfully repro the issue, here is the repo: https://github.com/laolarou726/NavigationBug

laolarou726 commented 2 years ago

@timunie Any update on this issue? Is that related to Avalonia's new render?

timunie commented 2 years ago

@laolarou726 I've checked out your sample today and tried to find the root cause. But honestly I have no idea what's going on. Looks like every second time the view is shown correctly.

laolarou726 commented 2 years ago

@laolarou726 I've checked out your sample today and tried to find the root cause. But honestly I have no idea what's going on. Looks like every second time the view is shown correctly.

Thanks. It's really strange, every time you navigate back to the first page you get nothing, but if you try again it will work.

Avabin commented 2 years ago

I am also affected by this. Can I ask for an rough estimate when the fix will be published?

grokys commented 2 years ago

@Avabin hopefully fixed by #9642 though I've not had time to check yet. If anyone wants to run the repro on that PR and check in the meantime, that would be appreciated!

laolarou726 commented 1 year ago

@Avabin hopefully fixed by #9642 though I've not had time to check yet. If anyone wants to run the repro on that PR and check in the meantime, that would be appreciated!

I just ran a test with Avalonia Version 11.0.999-cibuild0027216-beta. The problem seems to be more serious. Now the repro project can only successfully shows first two pages. After that, all the pages will not show up.

laolarou726 commented 1 year ago

@timunie @grokys I just did a test using the latest Avalonia 11.0 nightly build. The issue still exists and has become weirder. Now TransitioningContentControl can only show the first content. If I do further navigation. The control will be completely blank. Could you please reopen this issue?

maxkatz6 commented 1 year ago

@laolarou726 can you test with https://github.com/AvaloniaUI/Avalonia/pull/9803 build?

laolarou726 commented 1 year ago

@laolarou726 can you test with #9803 build?

It seems Nuget Nightly Source didn't push this version yet. I can not install this version using Avalonia Nightly Build Source.

maxkatz6 commented 1 year ago

@laolarou726 should be this one:

You can test this PR using the following package version. 11.0.999-cibuild0027927-beta. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]

But nuget cache takes a while to update.

laolarou726 commented 1 year ago

@laolarou726 should be this one:

You can test this PR using the following package version. 11.0.999-cibuild0027927-beta. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]

But nuget cache takes a while to update.

I still didn't find the latest build on the Nuget. Is there any way to discard the caches?

maxkatz6 commented 1 year ago

@laolarou726 maybe "11.0.999-cibuild0027937-beta" build from the master branch?

maxkatz6 commented 1 year ago

Is there any way to discard the caches?

If that still doesn't work, try dotnet nuget locals all --clear

laolarou726 commented 1 year ago

Is there any way to discard the caches?

If that still doesn't work, try dotnet nuget locals all --clear

Just cleared all the caches, but I still get:

image
timunie commented 1 year ago

I tried your sample by today and for me it seems to work as expected now.

laolarou726 commented 1 year ago

I tried your sample by today and for me it seems to work as expected now.

Tested today, it seems worked. Thank you guys so much!

timunie commented 1 year ago

@laolarou726 thanks for your findings, the great sample and the feedback. this helped a lot in sorting this one out.