xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

Binding not working in titleview using xamarin.forms ios but works in android #4520

Open prakash-malodiya opened 5 years ago

prakash-malodiya commented 5 years ago

I am using xamarin.forms (3.3.0.967583) version for developing application. In xamarin.forms iOS application I am unable to bind property from MVVM to xaml in titleview. But its working in Android application. I am not going to attach my code. I also see other related issues but not helping. See below sample code.

<NavigationPage.TitleView>
    <StackLayout HorizontalOptions="Start" 
        VerticalOptions="Center" 
        Margin="0" 
        Padding="{OnPlatform iOS='25,0,0,0', Android=0}">        
        <Label 
            Text="{Binding SelectedProduct.Title, 
            Mode=TwoWay}"
            TextColor="White" 
            FontSize="{StaticResource LargeFontSize}" 
            FontFamily="{StaticResource OpenSansRegular}" 
            VerticalTextAlignment="Center" />
    </StackLayout>
</NavigationPage.TitleView>
StephaneDelcroix commented 5 years ago

@tp16190 please use the template for filing new issues.

KennyDizi commented 5 years ago

FYI: I just tested with latest version 3.4, it's not show on Android platform, iOS haven't tested yet.

PureWeen commented 5 years ago

TitleView.zip

@tp16190 I've attached a repro showing binding working though I noticed that the layout width on iOS doesn't update if the width changes.

If you use a grid or set the stacklayout to a full width then binding should work. Let me know if that appears to be your issue

csuzw commented 5 years ago

I'm seeing this problem in UWP. This is not a height/width issue as there is plenty of room and I can see whether the label is with enable selection/display layout adorner options. The value being bound is also being bound elsewhere on the page and displays correctly.

    <NavigationPage.TitleView>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Text="Settings"/>
            <Label Grid.Row="1" Text="{Binding MyProperty, Mode=OneWay}"/>
        </Grid>
    </NavigationPage.TitleView>
llandru54 commented 4 years ago

I had the same thing happen to me - I'm on VS 2019, Windows. The first page I visited, displayed the correct page title. After that, it was grabbing the Title attribute from the menu item out of the Master Page. I don't know how it managed that, but I solved it by creating a property in my TitleContentView, and assigning it in the XAML for each content page that used it.