本文整理汇总了C#中MahApps.Metro.AppTheme类的典型用法代码示例。如果您正苦于以下问题:C# AppTheme类的具体用法?C# AppTheme怎么用?C# AppTheme使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AppTheme类属于MahApps.Metro命名空间,在下文中一共展示了AppTheme类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// </summary>
public void Load()
{
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Accent))
{
_styleAccent = ThemeManager.GetAccent(Properties.Settings.Default.Accent);
}
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Theme))
{
_styleTheme = ThemeManager.GetAppTheme(Properties.Settings.Default.Theme);
}
_mainWindow.Accent.SelectedValue = _styleAccent.Name;
switch (_styleTheme.Name)
{
case "BaseDark":
_mainWindow.Dark.IsChecked = true;
_mainWindow.Light.IsChecked = false;
break;
case "BaseLight":
_mainWindow.Dark.IsChecked = false;
_mainWindow.Light.IsChecked = true;
break;
}
SetStyle();
foreach (var accent in ThemeManager.Accents)
{
_mainWindow.Accent.Items.Add(accent.Name);
}
}
示例2: GetInverseAppThemeReturnsNullForMissingTheme
public async Task GetInverseAppThemeReturnsNullForMissingTheme()
{
await TestHost.SwitchToAppThread();
var appTheme = new AppTheme("TestTheme", new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml"));
AppTheme theme = ThemeManager.GetInverseAppTheme(appTheme);
Assert.Null(theme);
}
示例3: SwitchTheme
public void SwitchTheme(AppTheme newTheme)
{
Tuple<MahApps.Metro.AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Current);
switch (newTheme) {
case AppTheme.Light:
ThemeManager.ChangeAppStyle(
Current,
ThemeManager.GetAccent("Blue"),
ThemeManager.GetAppTheme("BaseLight"));
return;
case AppTheme.Dark:
ThemeManager.ChangeAppStyle(
Current,
ThemeManager.GetAccent("Green"),
ThemeManager.GetAppTheme("BaseDark"));
return;
default:
throw new NotImplementedException();
}
}
示例4: ChangeAppStyle
private static void ChangeAppStyle(ResourceDictionary resources, Tuple<AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme)
{
var themeChanged = false;
if (oldThemeInfo != null)
{
var oldAccent = oldThemeInfo.Item2;
if (oldAccent != null && oldAccent.Name != newAccent.Name)
{
var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source);
if (oldAccentResource != null)
{
resources.MergedDictionaries.Add(newAccent.Resources);
var ok = resources.MergedDictionaries.Remove(oldAccentResource);
themeChanged = true;
}
}
var oldTheme = oldThemeInfo.Item1;
if (oldTheme != null && oldTheme != newTheme)
{
var oldThemeResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldTheme.Resources.Source);
if (oldThemeResource != null)
{
resources.MergedDictionaries.Add(newTheme.Resources);
var ok = resources.MergedDictionaries.Remove(oldThemeResource);
themeChanged = true;
}
}
}
else
{
ChangeAppStyle(resources, newAccent, newTheme);
themeChanged = true;
}
if (themeChanged)
{
OnThemeChanged(newAccent, newTheme);
}
}
示例5: GetInverseAppTheme
/// <summary>
/// Gets the inverse <see cref="AppTheme" /> of the given <see cref="AppTheme"/>.
/// This method relies on the "Dark" or "Light" affix to be present.
/// </summary>
/// <param name="appTheme">The app theme.</param>
/// <returns>The inverse <see cref="AppTheme"/> or <c>null</c> if it couldn't be found.</returns>
/// <remarks>
/// Returns BaseLight, if BaseDark is given or vice versa.
/// Custom Themes must end with "Dark" or "Light" for this to work, for example "CustomDark" and "CustomLight".
/// </remarks>
public static AppTheme GetInverseAppTheme(AppTheme appTheme)
{
if (appTheme == null)
throw new ArgumentNullException("appTheme");
if (appTheme.Name.EndsWith("dark", StringComparison.InvariantCultureIgnoreCase))
{
return GetAppTheme(appTheme.Name.ToLower().Replace("dark", String.Empty) + "light");
}
if (appTheme.Name.EndsWith("light", StringComparison.InvariantCultureIgnoreCase))
{
return GetAppTheme(appTheme.Name.ToLower().Replace("light", String.Empty) + "dark");
}
return null;
}
示例6: OpenSettings_Click
private void OpenSettings_Click(object sender, RoutedEventArgs e)
{
if (!SettingsFlyout.IsOpen)
{
SettingsUsername.Text = getSelfName();
SettingsStatus.Text = getSelfStatusMessage();
SettingsNospam.Text = tox.GetNospam().ToString();
var style = ThemeManager.DetectAppStyle(Application.Current);
var accent = ThemeManager.GetAccent(style.Item2.Name);
oldAccent = accent;
if (accent != null)
AccentComboBox.SelectedItem = AccentComboBox.Items.Cast<AccentColorMenuData>().Single(a => a.Name == style.Item2.Name);
var theme = ThemeManager.GetAppTheme(style.Item1.Name);
oldAppTheme = theme;
if (theme != null)
AppThemeComboBox.SelectedItem = AppThemeComboBox.Items.Cast<AppThemeMenuData>().Single(a => a.Name == style.Item1.Name);
ViewModel.UpdateDevices();
foreach(var item in VideoDevicesComboBox.Items)
{
var device = (VideoMenuData)item;
if (device.Name == config.VideoDevice)
{
VideoDevicesComboBox.SelectedItem = item;
break;
}
}
if (InputDevicesComboBox.Items.Count - 1 >= config.InputDevice)
InputDevicesComboBox.SelectedIndex = config.InputDevice;
if (OutputDevicesComboBox.Items.Count - 1 >= config.OutputDevice)
OutputDevicesComboBox.SelectedIndex = config.OutputDevice;
ChatLogCheckBox.IsChecked = config.EnableChatLogging;
HideInTrayCheckBox.IsChecked = config.HideInTray;
PortableCheckBox.IsChecked = config.Portable;
AudioNotificationCheckBox.IsChecked = config.EnableAudioNotifications;
AlwaysNotifyCheckBox.IsChecked = config.AlwaysNotify;
SpellcheckCheckBox.IsChecked = config.EnableSpellcheck;
SpellcheckLanguageComboBox.SelectedItem = Enum.GetName(typeof(SpellcheckLanguage), config.SpellcheckLanguage);
FilterAudioCheckbox.IsChecked = config.FilterAudio;
if (!string.IsNullOrEmpty(config.ProxyAddress))
SettingsProxyAddress.Text = config.ProxyAddress;
if (config.ProxyPort != 0)
SettingsProxyPort.Text = config.ProxyPort.ToString();
foreach (ComboBoxItem item in ProxyTypeComboBox.Items)
{
if ((ToxProxyType)int.Parse((string)item.Tag) == config.ProxyType)
{
ProxyTypeComboBox.SelectedItem = item;
break;
}
}
}
SettingsFlyout.IsOpen = !SettingsFlyout.IsOpen;
}
示例7: OnThemeChanged
private static void OnThemeChanged(Accent newAccent, AppTheme newTheme)
{
SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs() { AppTheme = newTheme, Accent = newAccent });
}
示例8: DetectThemeFromResources
private static bool DetectThemeFromResources(ref AppTheme detectedTheme, ResourceDictionary dict)
{
var enumerator = dict.MergedDictionaries.GetEnumerator();
while (enumerator.MoveNext())
{
var currentRd = enumerator.Current;
AppTheme matched = null;
if ((matched = GetAppTheme(currentRd)) != null)
{
detectedTheme = matched;
enumerator.Dispose();
return true;
}
if (DetectThemeFromResources(ref detectedTheme, currentRd))
{
return true;
}
}
enumerator.Dispose();
return false;
}
示例9: ChangeAppStyle
/// <summary>
/// Sets the style of the specified <see cref="Application" /><paramref name="application" />
/// </summary>
/// <remarks>Miguel Santana 2015/05/03</remarks>
/// <param name="application"></param>
/// <param name="accentColor"></param>
/// <param name="themeColor"></param>
public static void ChangeAppStyle(this Application application, Accent accentColor, AppTheme themeColor = null)
{
ThemeManager.ChangeAppStyle(application, accentColor, themeColor ?? DefaultTheme);
}
示例10: SetTheme
/// <summary>
/// Theme of application style.
/// </summary>
/// <param name="sender"></param>
/// <param name="routedEventArgs"></param>
public void SetTheme(object sender, RoutedEventArgs routedEventArgs)
{
// get the theme from the current application
var style = ThemeManager.DetectAppStyle(Application.Current);
var radiobutton = (RadioButton)sender;
_styleTheme = style.Item1;
switch (radiobutton.Name)
{
case "Dark":
_styleTheme = ThemeManager.GetAppTheme("BaseDark");
break;
case "Light":
_styleTheme = ThemeManager.GetAppTheme("BaseLight");
break;
default:
_styleTheme = style.Item1;
break;
}
SetStyle();
}
示例11: GetAppTheme
/// <summary>
/// Gets app theme with the given app theme and theme type (light or dark).
/// </summary>
/// <param name="currentAppTheme"></param>
/// <param name="theme"></param>
/// <returns>AppTheme</returns>
public static AppTheme GetAppTheme(AppTheme currentAppTheme, Theme theme)
{
return GetAppTheme(currentAppTheme.Name, theme);
}
示例12: DarkButtonClick
private void DarkButtonClick(object sender, RoutedEventArgs e)
{
currentTheme = ThemeManager.AppThemes.First(x => x.Name == "BaseDark");
ThemeManager.ChangeAppStyle(Application.Current, currentAccent, currentTheme);
}
示例13: DetectThemeFromAppResources
internal static bool DetectThemeFromAppResources(out AppTheme detectedTheme)
{
detectedTheme = null;
return DetectThemeFromResources(ref detectedTheme, Application.Current.Resources);
}
示例14: LightButtonClick
private void LightButtonClick(object sender, RoutedEventArgs e)
{
currentTheme = ThemeManager.DefaultAppThemes.First(x => x.Name == "BaseLight");
ThemeManager.ChangeTheme(Application.Current, currentAccent, currentTheme);
}
示例15: GetThemeFromResources
internal static bool GetThemeFromResources(AppTheme presetTheme, ResourceDictionary dict, ref Tuple<AppTheme, Accent> detectedAccentTheme)
{
AppTheme currentTheme = presetTheme;
Accent matched = null;
if ((matched = GetAccent(dict)) != null)
{
detectedAccentTheme = Tuple.Create<AppTheme, Accent>(currentTheme, matched);
return true;
}
foreach (ResourceDictionary rd in dict.MergedDictionaries)
{
if (GetThemeFromResources(presetTheme, rd, ref detectedAccentTheme))
return true;
}
return false;
}