You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
64 lines
1.6 KiB
using CommunityToolkit.Maui.Behaviors;
|
|
|
|
namespace ex_CustomToolbar;
|
|
|
|
public partial class MainPage : ContentPage
|
|
{
|
|
int count = 0;
|
|
|
|
public MainPage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void OnCounterClicked(object sender, EventArgs e)
|
|
{
|
|
count++;
|
|
|
|
if (count == 1)
|
|
CounterBtn.Text = $"Clicked {count} time";
|
|
else
|
|
CounterBtn.Text = $"Clicked {count} times";
|
|
|
|
SemanticScreenReader.Announce(CounterBtn.Text);
|
|
}
|
|
|
|
void picker_SelectedIndexChanged(object source, EventArgs args)
|
|
{
|
|
string? chosenThemeString = picker.SelectedItem as string;
|
|
|
|
ResourceDictionary chosenTheme = chosenThemeString switch
|
|
{
|
|
"Dark" => new DarkTheme(),
|
|
"Light" => new LightTheme(),
|
|
"Color Blind" => new ColorBlindTheme(),
|
|
_ => new LightTheme()
|
|
};
|
|
|
|
ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
|
|
if (mergedDictionaries != null)
|
|
{
|
|
foreach(var dico in mergedDictionaries.Where(d => d is ICustomTheme).ToList())
|
|
{
|
|
mergedDictionaries.Remove(dico);
|
|
}
|
|
mergedDictionaries.Add(chosenTheme);
|
|
|
|
#if ANDROID
|
|
CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor((Color)Application.Current.Resources["PrimaryBackgroundColor"]);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
private void EllipsisClicked(object sender, EventArgs e)
|
|
{
|
|
secondaryMenu.IsVisible = !secondaryMenu.IsVisible;
|
|
}
|
|
|
|
private void BackgroundClicked(object sender, TappedEventArgs e)
|
|
{
|
|
secondaryMenu.IsVisible = false;
|
|
}
|
|
}
|
|
|