Omni_Philm
Omni_Philm
CC#
Created by Omni_Philm on 3/9/2023 in #help
❔ 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;

}
}
3 replies