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

ShellContent Title doesn't observe changes to bound properties #7453

Open
jskeet opened this issue May 24, 2022 · 8 comments · May be fixed by #24806
Open

ShellContent Title doesn't observe changes to bound properties #7453

jskeet opened this issue May 24, 2022 · 8 comments · May be fixed by #24806
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout delighter p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@jskeet
Copy link

jskeet commented May 24, 2022

Description

I have a shell with a page that itself has two tabs. The title of each tab can change dynamically, so it's set using <ShellContent Title="{Binding ...}" />. The binding is active initially, i.e. the title is taken from the binding - but if the bound property changes, the title doesn't change.

Steps to Reproduce

Code is in ShellContentTitleBinding.zip

The important parts are:

AppShell.xaml:

<?xml version="1.0" encoding="UTF-8" ?>
<Shell
    x:Class="ShellContentTitleBinding.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:ShellContentTitleBinding"
    Shell.FlyoutBehavior="Disabled">

    <TabBar>
        <Tab Title="Nested tabs">
            <ShellContent BindingContext="{Binding Tab1}" Title="{Binding Name}" ContentTemplate="{DataTemplate local:TabView}" />
            <ShellContent BindingContext="{Binding Tab2}" Title="{Binding Name}" ContentTemplate="{DataTemplate local:TabView}" />
        </Tab>
    </TabBar>
</Shell>

TabView.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ShellContentTitleBinding.TabView"
             Title="TabView">
    <StackLayout>
        <Label Text="{Binding Name}" />
        <Button Text="Change name" Clicked="ChangeName" />
    </StackLayout>
</ContentPage>

The ChangeName handler changes the property, which raises the appropriate event.

Importantly:

  • The initial value of the Name property is used in the title (so the binding is fundamentally making a connection)
  • The changed value of the Name property is visible in the label in the view (so the binding notification code seems to be okay)
  • The changed value isn't used in the title, as per this screenshot:

Screenshot of issue

Version with bug

Release Candidate 3 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

Android 11 / Pixel 5 / API 30, Windows10.0.19041.0

Did you find any workaround?

Not yet.

Relevant log output

No response

@jskeet jskeet added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 24, 2022
@PureWeen PureWeen added this to the 6.0.3xx-sr2 milestone May 24, 2022
@PureWeen PureWeen added p/2 Work that is important, but is currently not scheduled for release area-controls-shell Shell Navigation, Routes, Tabs, Flyout and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels May 24, 2022
@PureWeen
Copy link
Member

@jskeet

  1. There's definitely a bug here
  2. Once the bug is fixed, I just want to point out that the BindableProperty for Title by default uses OneTime binding. This decision was made for performance reasons when Shell was first created. I'm not the biggest fan of this as it feels unexpected and I have my doubts if it really does much for performance.

So you have to define the bindings yourself using OneWay

<ShellContent BindingContext="{Binding Tab1}" Title="{Binding Name, Mode=OneWay}" ContentTemplate="{DataTemplate local:TabView}" />
<ShellContent BindingContext="{Binding Tab2}" Title="{Binding Name, Mode=OneWay}" ContentTemplate="{DataTemplate local:TabView}" />

If you change the bindings to OneWay you'll see that Android works slightly better (if you click away and then back it updates). So there are still bugs here :-)

@jskeet
Copy link
Author

jskeet commented May 25, 2022

Wonderful - thank you so much for a swift diagnosis and workaround!

@jskeet
Copy link
Author

jskeet commented May 25, 2022

I can confirm that the workaround works well for me. (As it happens, the name is changed in the background in my real app, before the tab is even visible, so this actually addresses my issue completely. But it's not just about my existing use case, of course :)

@VincentBu
Copy link

repro with vs main build(32525.350.main)

@VincentBu VincentBu added the s/verified Verified / Reproducible Issue ready for Engineering Triage label May 26, 2022
@hartez hartez modified the milestones: 6.0-sr2, 6.0-sr3 Jun 27, 2022
@mattleibow mattleibow modified the milestones: 6.0-sr3, 6.0-servicing Aug 29, 2022
@Redth Redth modified the milestones: 6.0-servicing, Backlog Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@samhouts samhouts removed the s/verified Verified / Reproducible Issue ready for Engineering Triage label Apr 5, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels May 10, 2023
@XamlTest
Copy link

Verified this on Visual Studio Enterprise 17.6.0 Preview 7.0. Repro on Windows 11 and Android 13.0 with below Project:
ShellContentTitleBinding.zip

@PureWeen PureWeen self-assigned this Sep 13, 2023
@ewerspej
Copy link

ewerspej commented Oct 9, 2023

The same is true for other bindings on ShellContent elements, e.g. showing and hiding tabs in the TabBar by binding to the IsVisible property.

@Pottzork
Copy link

Pottzork commented Dec 1, 2023

I have the same issue where I have to click on a tab to get the binding to work. But I need it to work on first load.
And I also notice that the binding sets the correct value before view is rendered, but still I need to reload the view to get it to show.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout delighter p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants