Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Shell,TitleView, Android] TitleView Bindings does not work with Android #5650

Closed
HobDev opened this issue Mar 21, 2019 · 9 comments
Closed

Comments

@HobDev
Copy link

HobDev commented Mar 21, 2019

Description

The Text Property of Label.Text does not bind with ViewModel property in Android. Although it work if I do x:Reference with the page.

Steps to Reproduce

  1. Create a TitleView and add a label within .
  2. Bind Label.Text to a viewmodel property.
  3. Deploy to app to iOS and Android.

Expected Behavior

the Text should display on iOS and Android

Actual Behavior

Text does not display on Android navigation bar.

Basic Information

  • Version with issue:Xamarin.Forms-pre7
  • Last known good version:
  • IDE:Visual Studio for Mac preview
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

###Don't Work

<Shell.TitleView>
       <Grid HorizontalOptions="FillAndExpand" VerticalOptions="Center" >
           <Label HorizontalOptions="Center" VerticalOptions="Center"  FontSize="22" Text="{Binding Title}"/>
       </Grid>
   </Shell.TitleView>

Work

<Shell.TitleView>
       <Grid HorizontalOptions="FillAndExpand" VerticalOptions="Center" >
           <Label HorizontalOptions="Center" VerticalOptions="Center"  FontSize="22" Text="{Binding Source={x:Reference thisPage}, Path=BindingContext.Title}"/>
       </Grid>
   </Shell.TitleView>

@HobDev
Copy link
Author

HobDev commented Mar 21, 2019

It seems like Android have problem with any type of binding. Button commands also don't work with Android in Xamarin.Forms 4.

@samhouts samhouts added the e/3 🕒 3 label Mar 22, 2019
@PureWeen PureWeen self-assigned this Apr 12, 2019
AxelUser pushed a commit to AxelUser/Xamarin.Forms that referenced this issue Jun 15, 2019
…out (xamarin#5934) fixes xamarin#5650 fixes xamarin#5501

* propagate bindingcontext

* - add exception message and fix poorly named xaml file

* add ui test automation

* - fix unit test to represent new code

* - changed from ui test to unit test

* - propagate visual, parent, bc to titleview

* - style fixes
@gsemenov
Copy link

I have problem with binding in TitleView on ios (didn't test it on android) v.4.1.0.581479

@DaveNatalieTripArc
Copy link

DaveNatalieTripArc commented Aug 10, 2023

I am seeing this issue again in the latest Maui dotnet 8 Preview 7 release.

Doesn't work on Android or Windows.

@PureWeen
Copy link
Contributor

@DaveNatalieTripArc can you log an issue in the MAUI Repository?

I just tested locally against Preview7 and as far as I can tell the BC and Bindings are propagating fine.

@DaveNatalieTripArc
Copy link

DaveNatalieTripArc commented Aug 11, 2023

Maybe I misunderstood this issue. I am trying to have my App Shell bind to the title specified in the Content Page.

Something like this.

<Shell
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Shell.TitleView>
        <Label Text="{Binding Title}" />
    </Shell.TitleView>
</Shell>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             Title="I WANT TO BIND THIS VALUE">
</ContentPage>

Is this possible?

@PureWeen
Copy link
Contributor

Maybe I misunderstood this issue. I am trying to have my App Shell bind to the title specified in the Content Page.

Something like this.

<Shell
    x:Class="TripArc.ClientPortal.Mobile.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <Shell.TitleView>
        <Label Text="{Binding Title}" />
    </Shell.TitleView>
</Shell>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             Title="I WANT TO BIND THIS VALUE">
</ContentPage>

Is this possible?

you'd need to set the bindingcontext of the page to the contentpage itself or use a bindingpath to the ContentPage https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/binding-path

@DaveNatalieTripArc
Copy link

That's what's not working in Preview 7. I don't know if it worked in previous versions.

Here's what I tried.

<Shell
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Name="myShell">
    <Shell.TitleView>
        <Label BindingContext="{x:Reference myShell}" Text="{Binding Path=CurrentPage.Title}" TextColor="Red" />
    </Shell.TitleView>

I apologize, I simplified my example above to show what I want to accomplish, and not my actual code that wasn't working.

@PureWeen
Copy link
Contributor

That's what's not working in Preview 7. I don't know if it worked in previous versions.

Here's what I tried.

<Shell
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Name="myShell">
    <Shell.TitleView>
        <Label BindingContext="{x:Reference myShell}" Text="{Binding Path=CurrentPage.Title}" TextColor="Red" />
    </Shell.TitleView>

I apologize, I simplified my example above to show what I want to accomplish, and not my actual code that wasn't working.

CurrentPage isn't a bindable property

@DaveNatalieTripArc
Copy link

You said I should "use a bindingpath to the ContentPage"

What Path could I use that would get the me Title from the CurrentPage?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants