added requested theme dp to NotificationFlyout control since it is just a normal DependencyObject
This commit is contained in:
@@ -9,18 +9,18 @@
|
||||
|
||||
private void Theme_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
|
||||
{
|
||||
//switch (Theme.SelectedIndex)
|
||||
//{
|
||||
// case 0:
|
||||
// RequestedTheme = Windows.UI.Xaml.ElementTheme.Default;
|
||||
// break;
|
||||
// case 1:
|
||||
// RequestedTheme = Windows.UI.Xaml.ElementTheme.Dark;
|
||||
// break;
|
||||
// case 2:
|
||||
// RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;
|
||||
// break;
|
||||
//}
|
||||
switch (Theme.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
RequestedTheme = Windows.UI.Xaml.ElementTheme.Default;
|
||||
break;
|
||||
case 1:
|
||||
RequestedTheme = Windows.UI.Xaml.ElementTheme.Dark;
|
||||
break;
|
||||
case 2:
|
||||
RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,18 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
typeof(ImageSource), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(null, OnIconPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty RequestedThemeProperty =
|
||||
DependencyProperty.Register(nameof(RequestedTheme),
|
||||
typeof(ElementTheme), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(ElementTheme.Default, OnRequestedThemePropertyChanged));
|
||||
|
||||
public static DependencyProperty ContentProperty =
|
||||
DependencyProperty.Register(nameof(Content),
|
||||
typeof(UIElement), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(null));
|
||||
new PropertyMetadata(null, OnContentPropertyChanged));
|
||||
|
||||
internal event EventHandler ContentChanged;
|
||||
internal event EventHandler RequestedThemeChanged;
|
||||
internal event EventHandler IconSourceChanged;
|
||||
|
||||
public UIElement Content
|
||||
@@ -42,15 +48,43 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
set => SetValue(LightIconSourceProperty, value);
|
||||
}
|
||||
|
||||
public ElementTheme RequestedTheme
|
||||
{
|
||||
get => (ElementTheme)GetValue(RequestedThemeProperty);
|
||||
set => SetValue(RequestedThemeProperty, value);
|
||||
}
|
||||
|
||||
private static void OnContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyout;
|
||||
sender?.OnContentPropertyChanged();
|
||||
}
|
||||
|
||||
private static void OnIconPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyout;
|
||||
sender?.OnIconPropertyChanged();
|
||||
}
|
||||
|
||||
private static void OnRequestedThemePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var sender = dependencyObject as NotificationFlyout;
|
||||
sender?.OnRequestedThemePropertyChanged();
|
||||
}
|
||||
|
||||
private void OnContentPropertyChanged()
|
||||
{
|
||||
ContentChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void OnIconPropertyChanged()
|
||||
{
|
||||
IconSourceChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void OnRequestedThemePropertyChanged()
|
||||
{
|
||||
RequestedThemeChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-16
@@ -1,6 +1,4 @@
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
|
||||
namespace NotificationFlyout.Uwp.UI.Controls
|
||||
{
|
||||
@@ -10,18 +8,5 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
||||
{
|
||||
DefaultStyleKey = typeof(NotificationFlyoutPresenter);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
if (GetTemplateChild("ContentPresenter") is ContentControl contentPresenter)
|
||||
{
|
||||
BindingOperations.SetBinding(this, RequestedThemeProperty, new Binding
|
||||
{
|
||||
Source = contentPresenter.Content,
|
||||
Path = new PropertyPath(nameof(RequestedTheme)),
|
||||
Mode = BindingMode.TwoWay
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-6
@@ -36,19 +36,17 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
{
|
||||
_flyout.ContentChanged -= OnFlyoutContentChanged;
|
||||
_flyout.IconSourceChanged -= OnFlyoutIconSourceChanged;
|
||||
_flyout.RequestedThemeChanged -= OnFlyoutIconSourceChanged;
|
||||
}
|
||||
|
||||
_flyout = flyout;
|
||||
_flyout.ContentChanged += OnFlyoutContentChanged;
|
||||
_flyout.IconSourceChanged += OnFlyoutIconSourceChanged;
|
||||
_flyout.RequestedThemeChanged += OnFlyoutRequestedThemeChanged;
|
||||
|
||||
UpdateIcons();
|
||||
UpdateFlyoutContent();
|
||||
UpdateIcons();
|
||||
}
|
||||
|
||||
private void OnFlyoutIconSourceChanged(object sender, EventArgs args)
|
||||
{
|
||||
UpdateIcons();
|
||||
UpdateRequestedTheme();
|
||||
}
|
||||
|
||||
internal void HideFlyout()
|
||||
@@ -91,6 +89,16 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
UpdateFlyoutContent();
|
||||
}
|
||||
|
||||
private void OnFlyoutIconSourceChanged(object sender, EventArgs args)
|
||||
{
|
||||
UpdateIcons();
|
||||
}
|
||||
|
||||
private void OnFlyoutRequestedThemeChanged(object sender, EventArgs args)
|
||||
{
|
||||
UpdateRequestedTheme();
|
||||
}
|
||||
|
||||
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
||||
{
|
||||
ShowFlyout();
|
||||
@@ -192,6 +200,18 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
_notificationIconHelper.SetIcon(icon.Handle);
|
||||
}
|
||||
|
||||
private void UpdateRequestedTheme()
|
||||
{
|
||||
if (_flyout == null) return;
|
||||
|
||||
var requestedTheme = _flyout.RequestedTheme;
|
||||
|
||||
var flyoutHost = GetFlyoutHost();
|
||||
if (flyoutHost != null)
|
||||
{
|
||||
flyoutHost.RequestedTheme = requestedTheme;
|
||||
}
|
||||
}
|
||||
private void UpdateWindow()
|
||||
{
|
||||
if (!_isLoaded) return;
|
||||
|
||||
Reference in New Issue
Block a user