-
-
Notifications
You must be signed in to change notification settings - Fork 520
/
MahMetroWindow.xaml.cs
75 lines (60 loc) · 2.52 KB
/
MahMetroWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace FluentTest
{
using System;
using System.Windows;
using ControlzEx.Theming;
using Fluent;
using MahApps.Metro.Controls;
public partial class MahMetroWindow : IRibbonWindow
{
public MahMetroWindow()
{
this.InitializeComponent();
this.TestContent.Backstage.UseHighestAvailableAdornerLayer = false;
this.Loaded += this.MahMetroWindow_Loaded;
this.Closed += this.MahMetroWindow_Closed;
}
private void MahMetroWindow_Loaded(object? sender, RoutedEventArgs e)
{
this.TitleBar = this.FindChild<RibbonTitleBar>("RibbonTitleBar");
if (this.TitleBar is null)
{
throw new Exception("Ribbon titlebar could not be found.");
}
this.TitleBar.InvalidateArrange();
this.TitleBar.UpdateLayout();
// We need this inside this window because MahApps.Metro is not loaded globally inside the Fluent.Ribbon Showcase application.
// This code is not required in an application that loads the MahApps.Metro styles globally.
ThemeManager.Current.ChangeTheme(this, ThemeManager.Current.DetectTheme(Application.Current)!);
ThemeManager.Current.ThemeChanged += this.SyncThemes;
}
private void SyncThemes(object? sender, ThemeChangedEventArgs e)
{
if (e.Target == this)
{
return;
}
ThemeManager.Current.ChangeTheme(this, e.NewTheme);
}
private void MahMetroWindow_Closed(object? sender, EventArgs e)
{
ThemeManager.Current.ThemeChanged -= this.SyncThemes;
}
#region TitelBar
/// <summary>
/// Gets ribbon titlebar
/// </summary>
public RibbonTitleBar? TitleBar
{
get => (RibbonTitleBar?)this.GetValue(TitleBarProperty);
private set => this.SetValue(TitleBarPropertyKey, value);
}
// ReSharper disable once InconsistentNaming
private static readonly DependencyPropertyKey TitleBarPropertyKey = DependencyProperty.RegisterReadOnly(nameof(TitleBar), typeof(RibbonTitleBar), typeof(MahMetroWindow), new PropertyMetadata());
#pragma warning disable WPF0060
/// <summary>Identifies the <see cref="TitleBar"/> dependency property.</summary>
public static readonly DependencyProperty TitleBarProperty = TitleBarPropertyKey.DependencyProperty;
#pragma warning restore WPF0060
#endregion
}
}