C
C#2y ago
Omni_Philm

❔ Being able to change Navigation title of a page at runtime

I am trying to write some code that will change the navigation title of a page during runtime. I am trying to implement the solution found on this page:https://stackoverflow.com/questions/45834558/how-to-dynamically-change-the-navigation-bar-title-when-contentview-changes However, it is not working for me. Could I get a second pair of eyes and check to see what I am missing? XAML Code:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:The_Juice.ViewModel"
x:Class="The_Juice.SubclubMenu"
x:Name="_self"
x:DataType="viewModels:BlendDescriptionModel"
Title="{Binding Path=Content.Title, Source={x:Reference _self}}">
<ScrollView>
<VerticalStackLayout>
<Image Source="{Binding ClubImage}"></Image>
<Label Text="{Binding ClubName}"></Label>
<Label Text="Ingredients:"></Label>
<Label Text="{Binding ClubIngredients}"></Label>
<Label Text="{Binding ClubDescription}"></Label>
<Button Text="Sign Up" x:Name="SignUpButton"></Button>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModels="clr-namespace:The_Juice.ViewModel"
x:Class="The_Juice.SubclubMenu"
x:Name="_self"
x:DataType="viewModels:BlendDescriptionModel"
Title="{Binding Path=Content.Title, Source={x:Reference _self}}">
<ScrollView>
<VerticalStackLayout>
<Image Source="{Binding ClubImage}"></Image>
<Label Text="{Binding ClubName}"></Label>
<Label Text="Ingredients:"></Label>
<Label Text="{Binding ClubIngredients}"></Label>
<Label Text="{Binding ClubDescription}"></Label>
<Button Text="Sign Up" x:Name="SignUpButton"></Button>
</VerticalStackLayout>
</ScrollView>
</ContentPage>
C# Code
namespace The_Juice;
using The_Juice.ViewModel;

public partial class SubclubMenu : ContentPage{
BlendDescriptionModel SelectedDescription;
public static readonly BindableProperty TitleProperty = BindableProperty.Create("Title",
typeof(string),
typeof(SubclubMenu),
defaultValue: null,
defaultBindingMode: BindingMode.OneWayToSource);
public string Title{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public SubclubMenu(BlendDescriptionModel Value{
InitializeComponent();
SelectedDescription = Value;
Title = SelectedDescription.ClubName;

}
}
namespace The_Juice;
using The_Juice.ViewModel;

public partial class SubclubMenu : ContentPage{
BlendDescriptionModel SelectedDescription;
public static readonly BindableProperty TitleProperty = BindableProperty.Create("Title",
typeof(string),
typeof(SubclubMenu),
defaultValue: null,
defaultBindingMode: BindingMode.OneWayToSource);
public string Title{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public SubclubMenu(BlendDescriptionModel Value{
InitializeComponent();
SelectedDescription = Value;
Title = SelectedDescription.ClubName;

}
}
Stack Overflow
How to dynamically change the navigation bar title when ContentView...
I'm working on a new very basic application with Xamarin.Forms and I have a doubt... I can't figure it out how to do that since I do not have much experience with Xamarin at all. I got a ContentP...
2 Replies
Omni_Philm
Omni_PhilmOP2y ago
Please note, that I did delete some code to make it fit into the post. But the relevant code for this post remains
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server