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

[Navigation] Uno.Extensions.Navigation.UI..Region Logger not set prior to navigating in MVUX project. #2159

Closed
MarkAllan007 opened this issue Jan 31, 2024 · 10 comments · Fixed by #2403
Assignees
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.

Comments

@MarkAllan007
Copy link

Current behavior

Use Uno Wizard to setup a MVUX project which allows us to use NavigationView paired with Regions.
With minimum modifications, update the shells.xaml.cs xaml to include the markup below.
Leave most of the app.cs file the same. I removed the secondpage from the project.

A. shell.xaml file should contain two groups of markup. One group is commented out, the other is not. Uncomment and run the "NavigationView" markup. The execution reports an error: ... Region Logger is null.

B. Comment out the "NavigationView" markup and uncomment the "extended splash screen" markup. Run the "extended splash screen" markup. The Region Logger is set to a valid logger.

Expected behavior

The expected behavior for both sets of markup is that the Region Logger is properly set to a valid logger and will not throw and exception.

How to reproduce it (as minimally and precisely as possible)

Use Uno Wizard to setup a MVUX project which allows us to use NavigationView paired with Regions.
With minimum modifications, update the shells.xaml.cs xaml to include the markup below.
Leave most of the app.cs file the same. I removed the secondpage from the project.

A. shell.xaml file should contain two groups of markup. One group is commented out, the other is not. Uncomment and run the "NavigationView" markup. The execution reports an error: ... Region Logger is null.

B. Comment out the "NavigationView" markup and uncomment the "extended splash screen" markup. Run the "extended splash screen" markup. The Region Logger is set to a valid logger.

Sample markup to test with.

<utu:NavigationBar Content="Main Page"  />

<muxc:NavigationView Grid.Row="1" x:Name="NavView" uen:Region.Attached="True">
  <muxc:NavigationView.MenuItems>
    <muxc:NavigationViewItem Content="Main" uen:Region.Name="Main" />
  </muxc:NavigationView.MenuItems>

  <muxc:NavigationView.Content>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Grid uen:Region.Attached="True">
        <Grid Visibility="Collapsed" uen:Region.Name="Main">
          <TextBlock Text="Main"
                              FontSize="24"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center" />
        </Grid>

      </Grid>
    </Grid>

  </muxc:NavigationView.Content>
</muxc:NavigationView>

Workaround

I don't know of a work around.

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

Affected platforms

No response

IDE

Visual Studio 2022

IDE version

17.8.5

Relevant plugins

Uno Platform 5.1.22.24

Anything else we need to know?

I walking through your examples. I start with using your wizard to create projects. I am testing some of Uno features the systems use of MVUX for navigation. But wanted to see how to use it with the NavigationView tools. I'm looking to see the extent use cases that allow for freestyle navigation.

Thanks so much,
Mark Allan

@MarkAllan007 MarkAllan007 added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification. labels Jan 31, 2024
@MarkAllan007
Copy link
Author

Your system stripped out some of the markup I pasted. Here is the markup that I have in my shell.xaml file.
The markup is pretty basic.
Thank you,
Mark Allan

<utu:NavigationBar Content="Main Page"  />

<muxc:NavigationView Grid.Row="1" x:Name="NavView" uen:Region.Attached="True">
  <muxc:NavigationView.MenuItems>
    <muxc:NavigationViewItem Content="Main" uen:Region.Name="Main" />
  </muxc:NavigationView.MenuItems>

  <muxc:NavigationView.Content>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Grid uen:Region.Attached="True">
        <Grid Visibility="Collapsed" uen:Region.Name="Main">
          <TextBlock Text="Main"
                              FontSize="24"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center" />
        </Grid>

      </Grid>
    </Grid>

  </muxc:NavigationView.Content>
</muxc:NavigationView>

@MarkAllan007
Copy link
Author

Well, again your editor tool stripped out the markup.
What can I do?
Mark Allan.

@jeromelaban jeromelaban transferred this issue from unoplatform/uno Feb 1, 2024
@MarkAllan007
Copy link
Author

Shell xaml for testing uno platform app startup 001

@MarkAllan007
Copy link
Author

After doing some regression testing, my impression is this attribute [ uen:Region.Attached="True" ] is rerouting the app hosting's initialization. Either intentionally or by causing an exception?

@xperiandri
Copy link

I have similar issue but my error make no sense at all

<UserControl x:Class="eCierge.Console.Presentation.Shell"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:eCierge.Console.Presentation"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:uen="using:Uno.Extensions.Navigation.UI"
      xmlns:utu="using:Uno.Toolkit.UI"
      mc:Ignorable="d"
      d:DesignHeight="300"
      d:DesignWidth="400">
  <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <utu:NavigationBar />
    <NavigationView x:Name="NavView"
                    Grid.Row="1"
                    uen:Region.Attached="True"
                    >
      <NavigationView.MenuItems>
        <NavigationViewItem Content="Main" uen:Region.Name="Main" />
        <NavigationViewItem Content="Second" uen:Region.Name="Second" />
      </NavigationView.MenuItems>

      <!--<Frame uen:Region.Attached="True"/>-->
    </NavigationView>
    <!--<utu:ExtendedSplashScreen x:Name="Splash"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch">
    <utu:ExtendedSplashScreen.LoadingContentTemplate>
      <DataTemplate>
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="2*" />
            <RowDefinition />
          </Grid.RowDefinitions>

          <ProgressRing IsActive="True"
                  Grid.Row="1"
                  VerticalAlignment="Center"
                  HorizontalAlignment="Center"
                  Height="100"
                  Width="100" />
        </Grid>
      </DataTemplate>
    </utu:ExtendedSplashScreen.LoadingContentTemplate>
  </utu:ExtendedSplashScreen>-->
  </Grid>
</UserControl>

My shell crashes, in any case, I have uen:Region.Attached="True" placed either on the NavigationView or the root Grid

image
image

@xperiandri
Copy link

So I've figured out what is the issue. The ExtendedSplashScreen added to the template not just for fun or demo purposes.
Region needs a logger
Logger is being set by hosted service
Hosted service starts with some delay
ExtendedSplashScreen reacts to event of all hosted services being started

Hence if you try to use Region in the Shell then logger is not set yet.

@nickrandolph it is very confusing! There is no mentions of such logic anywhere! I spent 1 day figuring out why this happens. Which required me to copy 2 projects from Uno.Extenstions to a sample solution from template with my code to figure out that.

And calling a splash screen as shell is very confusing too. Because the shell is where you put NavigationView and TabBar.
And if you cannot put NavigationView or TabBar into an ExtendedSplashScreen which is a part of shell it is no longer a shell.
cc @jeromelaban

@sasakrsmanovic
Copy link

@weitzhandler @lukeblevins FYI too as I know you did some documentation on this front.

@xperiandri
Copy link

@MarkAllan007 were you able to verify that my suggestion works?

@MarkAllan007
Copy link
Author

MarkAllan007 commented Apr 16, 2024

@xperiandri Sorry this error slowed you down. Glad you found a work around.

No, I have not been working on a solution for this. I did trace through this apps initialization, looking at differences in the markup, leading to the exception.

I do not have a stake in using Regions, yet. I was/am curious about them. I was looking .Net 8 & Uno's implementation of NavigationView/ViewItems. We can embed NavigationViewItems in user controls.

I was looking at Regions, because I came across this error: #2163

In setting up my NavigtionViewItems, I found that my ShellViewModel's constructor was not being instantiated. Some slight changes in the shells xaml statement, can change something.

It looks like Regions maybe a better, easier tool to use, than using NavigatioViewItems paired with boil-plate code-behind. This would be nice to test this.

If I find some time, I will definitely look for a clean solution. :-)

@nickrandolph
Copy link
Contributor

@xperiandri @MarkAllan007 apologies for the delay in getting to this - documentation on regions is in the works (hopefully this week) and I realise that the ShellView/ViewModel may be confusing. If you're using NavigationView/TabBar they should go on your MainPage, rather than the ShellView.

@nickrandolph nickrandolph changed the title Uno.Extensions.Navigation.UI..Region Logger not set prior to navigating in MVUX project. [Navigation] Uno.Extensions.Navigation.UI..Region Logger not set prior to navigating in MVUX project. May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants