Hello,
You can do it by Messenger - .NET Community Toolkit | Microsoft Learn and change color of status bar and navigation bar at the runtime by SetTabBarBackgroundColor
, SetBackgroundColor
For example, you create a Messager in the background code.
// Create a message
public class ColorChangedMessage : ValueChangedMessage<Color>
{
public ColorChangedMessage(Color color) : base(color)
{
}
}
When you have a button click event, after clicking the button, color of status bar and navigation bar will be changed at the runtime, you can send a message.
WeakReferenceMessenger.Default.Send<ColorChangedMessage>(new ColorChangedMessage(Color.FromRgb(255, 0, 0)));
Then open your appshell.xaml.cs
, you could register this message and get the color from the button click event, you can refer to the following code.
public AppShell()
{
InitializeComponent();
// Register a message in some module
WeakReferenceMessenger.Default.Register<ColorChangedMessage>(this, (r, m) =>
{
var color=m.Value as Color;
SetTabBarBackgroundColor(this, color);
SetBackgroundColor(this, color);
});
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.