diff --git a/samples/NotificationFlyoutSample.Host/App.xaml b/samples/NotificationFlyoutSample.Host/App.xaml
index acca37f..15ff085 100644
--- a/samples/NotificationFlyoutSample.Host/App.xaml
+++ b/samples/NotificationFlyoutSample.Host/App.xaml
@@ -3,4 +3,4 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
-
+
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample.Host/App.xaml.cs b/samples/NotificationFlyoutSample.Host/App.xaml.cs
index 83f9881..dda90fb 100644
--- a/samples/NotificationFlyoutSample.Host/App.xaml.cs
+++ b/samples/NotificationFlyoutSample.Host/App.xaml.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Data;
-using System.Linq;
-using System.Threading.Tasks;
-using System.Windows;
+using System.Windows;
namespace NotificationFlyoutSample.Host
{
@@ -14,4 +8,4 @@ namespace NotificationFlyoutSample.Host
public partial class App : Application
{
}
-}
+}
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample.Host/AssemblyInfo.cs b/samples/NotificationFlyoutSample.Host/AssemblyInfo.cs
index 8b5504e..4f943de 100644
--- a/samples/NotificationFlyoutSample.Host/AssemblyInfo.cs
+++ b/samples/NotificationFlyoutSample.Host/AssemblyInfo.cs
@@ -7,4 +7,4 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
-)]
+)]
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample.Host/Program.cs b/samples/NotificationFlyoutSample.Host/Program.cs
index 9195f20..80b39c0 100644
--- a/samples/NotificationFlyoutSample.Host/Program.cs
+++ b/samples/NotificationFlyoutSample.Host/Program.cs
@@ -12,11 +12,11 @@ namespace NotificationFlyoutSample.Host
{
var app = new App();
new NotificationFlyoutApplication
- {
+ {
Flyout = new Shell()
};
app.Run();
}
}
}
-}
+}
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample.sln b/samples/NotificationFlyoutSample.sln
index 9079ea8..909956b 100644
--- a/samples/NotificationFlyoutSample.sln
+++ b/samples/NotificationFlyoutSample.sln
@@ -18,8 +18,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotificationFlyout.Wpf.UI",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotificationFlyout.Wpf.UI.Controls", "..\src\NotificationFlyout.Wpf.UI.Controls\NotificationFlyout.Wpf.UI.Controls.csproj", "{094A2030-C430-490B-AB26-205385A0D4BF}"
EndProject
-Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "NotificationFlyoutSample.Package", "NotificationFlyoutSample.Package\NotificationFlyoutSample.Package.wapproj", "{E2F52D15-A3BB-41CE-901C-AB491C50327A}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotificationFlyout.Uwp.UI", "..\src\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj", "{AFCE4980-A641-4BBB-A745-F0D4E54A0D86}"
EndProject
Global
@@ -143,36 +141,6 @@ Global
{094A2030-C430-490B-AB26-205385A0D4BF}.Release|x64.Build.0 = Release|x64
{094A2030-C430-490B-AB26-205385A0D4BF}.Release|x86.ActiveCfg = Release|Any CPU
{094A2030-C430-490B-AB26-205385A0D4BF}.Release|x86.Build.0 = Release|Any CPU
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|Any CPU.ActiveCfg = Debug|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|Any CPU.Build.0 = Debug|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|Any CPU.Deploy.0 = Debug|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|ARM.ActiveCfg = Debug|ARM
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|ARM.Build.0 = Debug|ARM
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|ARM.Deploy.0 = Debug|ARM
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|ARM64.ActiveCfg = Debug|ARM64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|ARM64.Build.0 = Debug|ARM64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|ARM64.Deploy.0 = Debug|ARM64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|x64.ActiveCfg = Debug|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|x64.Build.0 = Debug|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|x64.Deploy.0 = Debug|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|x86.ActiveCfg = Debug|x86
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|x86.Build.0 = Debug|x86
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Debug|x86.Deploy.0 = Debug|x86
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|Any CPU.Build.0 = Release|Any CPU
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|Any CPU.Deploy.0 = Release|Any CPU
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|ARM.ActiveCfg = Release|ARM
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|ARM.Build.0 = Release|ARM
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|ARM.Deploy.0 = Release|ARM
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|ARM64.ActiveCfg = Release|ARM64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|ARM64.Build.0 = Release|ARM64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|ARM64.Deploy.0 = Release|ARM64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|x64.ActiveCfg = Release|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|x64.Build.0 = Release|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|x64.Deploy.0 = Release|x64
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|x86.ActiveCfg = Release|x86
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|x86.Build.0 = Release|x86
- {E2F52D15-A3BB-41CE-901C-AB491C50327A}.Release|x86.Deploy.0 = Release|x86
{AFCE4980-A641-4BBB-A745-F0D4E54A0D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFCE4980-A641-4BBB-A745-F0D4E54A0D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFCE4980-A641-4BBB-A745-F0D4E54A0D86}.Debug|ARM.ActiveCfg = Debug|Any CPU
diff --git a/samples/NotificationFlyoutSample/App.xaml b/samples/NotificationFlyoutSample/App.xaml
index 82efc8e..d667a0b 100644
--- a/samples/NotificationFlyoutSample/App.xaml
+++ b/samples/NotificationFlyoutSample/App.xaml
@@ -6,4 +6,4 @@
-
+
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample/App.xaml.cs b/samples/NotificationFlyoutSample/App.xaml.cs
index ed596a9..a6ced91 100644
--- a/samples/NotificationFlyoutSample/App.xaml.cs
+++ b/samples/NotificationFlyoutSample/App.xaml.cs
@@ -9,4 +9,4 @@ namespace NotificationFlyoutSample
Initialize();
}
}
-}
+}
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample/Properties/AssemblyInfo.cs b/samples/NotificationFlyoutSample/Properties/AssemblyInfo.cs
index 16d6268..2cfc1ca 100644
--- a/samples/NotificationFlyoutSample/Properties/AssemblyInfo.cs
+++ b/samples/NotificationFlyoutSample/Properties/AssemblyInfo.cs
@@ -1,8 +1,7 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-// General Information about an assembly is controlled through the following
+// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NotificationFlyoutSample")]
@@ -17,11 +16,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values:
//
// Major Version
-// Minor Version
+// Minor Version
// Build Number
// Revision
//
-// You can specify all the values or you can default the Build and Revision Numbers
+// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
diff --git a/samples/NotificationFlyoutSample/Properties/Default.rd.xml b/samples/NotificationFlyoutSample/Properties/Default.rd.xml
index af00722..7454086 100644
--- a/samples/NotificationFlyoutSample/Properties/Default.rd.xml
+++ b/samples/NotificationFlyoutSample/Properties/Default.rd.xml
@@ -6,7 +6,7 @@
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
To fully enable reflection for App1.MyClass and all of its public/private members
-
+
To enable dynamic creation of the specific instantiation of AppClass over System.Int32
@@ -22,10 +22,7 @@
the application package. The asterisks are not wildcards.
-->
-
-
+
-
-
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample/Shell.xaml b/samples/NotificationFlyoutSample/Shell.xaml
index 3f44d5d..265763a 100644
--- a/samples/NotificationFlyoutSample/Shell.xaml
+++ b/samples/NotificationFlyoutSample/Shell.xaml
@@ -6,9 +6,11 @@
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
IconSource="/Assets/Icon.ico"
LightIconSource="/Assets/Icon-Light.ico">
-
-
-
+
+
+
+
+
-
+
@@ -83,4 +88,4 @@
-
+
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample/Shell.xaml.cs b/samples/NotificationFlyoutSample/Shell.xaml.cs
index f1f9ba2..f7e0b73 100644
--- a/samples/NotificationFlyoutSample/Shell.xaml.cs
+++ b/samples/NotificationFlyoutSample/Shell.xaml.cs
@@ -14,9 +14,11 @@
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;
@@ -35,4 +37,4 @@
app.OpenAsWindow();
}
}
-}
+}
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample/WindowContent.xaml b/samples/NotificationFlyoutSample/WindowContent.xaml
index 2088c37..1d82c40 100644
--- a/samples/NotificationFlyoutSample/WindowContent.xaml
+++ b/samples/NotificationFlyoutSample/WindowContent.xaml
@@ -24,4 +24,4 @@
-
+
\ No newline at end of file
diff --git a/samples/NotificationFlyoutSample/WindowContent.xaml.cs b/samples/NotificationFlyoutSample/WindowContent.xaml.cs
index 2522012..6b5befb 100644
--- a/samples/NotificationFlyoutSample/WindowContent.xaml.cs
+++ b/samples/NotificationFlyoutSample/WindowContent.xaml.cs
@@ -1,17 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Navigation;
+using Windows.UI.Xaml.Controls;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
@@ -24,4 +11,4 @@ namespace NotificationFlyoutSample
this.InitializeComponent();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout.Uwp.UI.Controls.csproj b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout.Uwp.UI.Controls.csproj
index 347e181..442fa07 100644
--- a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout.Uwp.UI.Controls.csproj
+++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout.Uwp.UI.Controls.csproj
@@ -13,7 +13,7 @@
1.0.0
-
+
Designer
MSBuild:Compile
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.cs b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.cs
deleted file mode 100644
index 4a945dd..0000000
--- a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System.Collections.Generic;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-
-namespace NotificationFlyout.Uwp.UI.Controls
-{
- internal class ContextMenuFlyoutHost : Control
- {
- private MenuFlyout _flyout;
- private Grid _root;
-
- public ContextMenuFlyoutHost()
- {
- DefaultStyleKey = typeof(ContextMenuFlyoutHost);
- }
-
- public void HideFlyout()
- {
- if (_flyout == null) return;
- _flyout.Hide();
- }
-
- public void ShowFlyout()
- {
- if (_root == null) return;
- if (_flyout == null) return;
-
- _flyout.ShowAt(_root, new FlyoutShowOptions { Placement = FlyoutPlacementMode.BottomEdgeAlignedLeft, ShowMode = FlyoutShowMode.TransientWithDismissOnPointerMoveAway });
- }
-
- protected override void OnApplyTemplate()
- {
- _root = GetTemplateChild("Root") as Grid;
- _flyout = GetTemplateChild("Flyout") as MenuFlyout;
- }
-
- internal void SetMenuItems(IList addedItems, IList removedItems = null)
- {
- if (_flyout == null) return;
-
- if (removedItems != null)
- {
- foreach (var item in removedItems)
- {
- _flyout.Items.Remove(item);
- }
- }
-
- foreach (var item in addedItems)
- {
- _flyout.Items.Add(item);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyout.cs b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyout.cs
index b81f8a0..f74e876 100644
--- a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyout.cs
+++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyout.cs
@@ -1,10 +1,5 @@
using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.Linq;
using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
@@ -13,6 +8,11 @@ namespace NotificationFlyout.Uwp.UI.Controls
[ContentProperty(Name = "Content")]
public class NotificationFlyout : DependencyObject
{
+ public static readonly DependencyProperty FlyoutPresenterStyleProperty =
+ DependencyProperty.Register(nameof(FlyoutPresenterStyle),
+ typeof(Style), typeof(NotificationFlyout),
+ new PropertyMetadata(null));
+
public static readonly DependencyProperty IconSourceProperty =
DependencyProperty.Register(nameof(IconSource),
typeof(ImageSource), typeof(NotificationFlyout),
@@ -21,48 +21,45 @@ namespace NotificationFlyout.Uwp.UI.Controls
public static readonly DependencyProperty LightIconSourceProperty =
DependencyProperty.Register(nameof(LightIconSource),
typeof(ImageSource), typeof(NotificationFlyout),
- new PropertyMetadata(null, OnIconPropertyChanged));
+ new PropertyMetadata(null));
public static readonly DependencyProperty RequestedThemeProperty =
DependencyProperty.Register(nameof(RequestedTheme),
typeof(ElementTheme), typeof(NotificationFlyout),
- new PropertyMetadata(ElementTheme.Default, OnRequestedThemePropertyChanged));
-
- public static INotificationFlyoutApplication _applicationInstance;
+ new PropertyMetadata(ElementTheme.Default));
public static DependencyProperty ContentProperty =
- DependencyProperty.Register(nameof(Content),
+ DependencyProperty.Register(nameof(Content),
typeof(UIElement), typeof(NotificationFlyout),
- new PropertyMetadata(null, OnContentPropertyChanged));
-
- public static DependencyProperty ContextMenuItemsProperty =
- DependencyProperty.Register(nameof(ContextMenuItems),
- typeof(IList), typeof(NotificationFlyout),
new PropertyMetadata(null));
- public NotificationFlyout()
- {
- ContextMenuItems = new ObservableCollection();
- (ContextMenuItems as INotifyCollectionChanged).CollectionChanged += OnContextMenuItemsChanged;
- }
- internal event EventHandler ContentChanged;
+ public static DependencyProperty ContextMenuProperty =
+ DependencyProperty.Register(nameof(ContextMenu),
+ typeof(NotificationFlyoutContextMenu), typeof(NotificationFlyout),
+ new PropertyMetadata(null, OnContextMenuPropertyChanged));
+
+ private static INotificationFlyoutApplication _applicationInstance;
+
+ internal event EventHandler ContextMenuChanged;
internal event EventHandler IconSourceChanged;
- internal event EventHandler MenuItemsChanged;
-
- internal event EventHandler RequestedThemeChanged;
-
public UIElement Content
{
get => (UIElement)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
- public IList ContextMenuItems
+ public NotificationFlyoutContextMenu ContextMenu
{
- get => (IList)GetValue(ContextMenuItemsProperty);
- set => SetValue(ContextMenuItemsProperty, value);
+ get => (NotificationFlyoutContextMenu)GetValue(ContextMenuProperty);
+ set => SetValue(ContextMenuProperty, value);
+ }
+
+ public Style FlyoutPresenterStyle
+ {
+ get => (Style)GetValue(FlyoutPresenterStyleProperty);
+ set => SetValue(FlyoutPresenterStyleProperty, value);
}
public ImageSource IconSource
@@ -83,20 +80,14 @@ namespace NotificationFlyout.Uwp.UI.Controls
set => SetValue(RequestedThemeProperty, value);
}
- public static INotificationFlyoutApplication GetApplication()
- {
- return _applicationInstance;
- }
+ public static INotificationFlyoutApplication GetApplication() => _applicationInstance;
- internal static void SetApplication(INotificationFlyoutApplication application)
- {
- _applicationInstance = application;
- }
+ internal static void SetApplication(INotificationFlyoutApplication application) => _applicationInstance = application;
- private static void OnContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
+ private static void OnContextMenuPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
{
var sender = dependencyObject as NotificationFlyout;
- sender?.OnContentPropertyChanged();
+ sender?.OnContextMenuPropertyChanged();
}
private static void OnIconPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
@@ -105,46 +96,14 @@ namespace NotificationFlyout.Uwp.UI.Controls
sender?.OnIconPropertyChanged();
}
- private static void OnRequestedThemePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
+ private void OnContextMenuPropertyChanged()
{
- var sender = dependencyObject as NotificationFlyout;
- sender?.OnRequestedThemePropertyChanged();
- }
-
- private void OnContentPropertyChanged()
- {
- ContentChanged?.Invoke(this, EventArgs.Empty);
- }
-
- private void OnContextMenuItemsChanged(object sender, NotifyCollectionChangedEventArgs args)
- {
- var addedItems = args.NewItems.Cast().ToList();
- var removedItems = args.NewItems.Cast().ToList();
-
- MenuItemsChanged?.Invoke(this, new NotificationFlyoutMenuItemsChangedEventArgs(addedItems, removedItems));
+ ContextMenuChanged?.Invoke(this, EventArgs.Empty);
}
private void OnIconPropertyChanged()
{
IconSourceChanged?.Invoke(this, EventArgs.Empty);
}
-
- private void OnRequestedThemePropertyChanged()
- {
- RequestedThemeChanged?.Invoke(this, EventArgs.Empty);
- }
}
-
- internal class NotificationFlyoutMenuItemsChangedEventArgs : EventArgs
- {
- public NotificationFlyoutMenuItemsChangedEventArgs(IList addedItems, IList removedItems)
- {
- AddedItems = addedItems;
- RemovedItems = removedItems;
- }
-
- public IList AddedItems { get; private set; }
-
- public IList RemovedItems { get; private set; }
- }
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenu.cs b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenu.cs
new file mode 100644
index 0000000..c154235
--- /dev/null
+++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenu.cs
@@ -0,0 +1,25 @@
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Markup;
+
+namespace NotificationFlyout.Uwp.UI.Controls
+{
+ [ContentProperty(Name = "MenuItems")]
+ public class NotificationFlyoutContextMenu : DependencyObject
+ {
+ public static DependencyProperty MenuItemsProperty =
+ DependencyProperty.Register(nameof(MenuItems),
+ typeof(IList), typeof(NotificationFlyout),
+ new PropertyMetadata(null));
+
+ public NotificationFlyoutContextMenu() => MenuItems = new ObservableCollection();
+
+ public IList MenuItems
+ {
+ get => (IList)GetValue(MenuItemsProperty);
+ set => SetValue(MenuItemsProperty, value);
+ }
+ }
+}
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.cs b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.cs
new file mode 100644
index 0000000..7c98ee4
--- /dev/null
+++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.cs
@@ -0,0 +1,100 @@
+using System.Collections.Specialized;
+using System.Linq;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls.Primitives;
+
+namespace NotificationFlyout.Uwp.UI.Controls
+{
+ internal class NotificationFlyoutContextMenuFlyoutHost : Control
+ {
+ private NotificationFlyout _flyout;
+ private MenuFlyout _menuFlyout;
+ private Grid _root;
+
+ public NotificationFlyoutContextMenuFlyoutHost() => DefaultStyleKey = typeof(NotificationFlyoutContextMenuFlyoutHost);
+
+ public void HideFlyout()
+ {
+ if (_menuFlyout == null) return;
+ _menuFlyout.Hide();
+ }
+
+ public void ShowFlyout()
+ {
+ if (_root == null) return;
+ if (_menuFlyout == null) return;
+
+ _menuFlyout.ShowAt(_root, new FlyoutShowOptions
+ {
+ Placement = FlyoutPlacementMode.BottomEdgeAlignedLeft,
+ ShowMode = FlyoutShowMode.TransientWithDismissOnPointerMoveAway
+ });
+ }
+
+ internal void SetOwningFlyout(NotificationFlyout flyout)
+ {
+ if (_flyout != null)
+ {
+ (_flyout.ContextMenu.MenuItems as INotifyCollectionChanged).CollectionChanged -= OnContextMenuItemsChanged;
+ }
+
+ _flyout = flyout;
+
+ var contextMenu = _flyout.ContextMenu;
+ if (contextMenu == null) return;
+
+ (contextMenu.MenuItems as INotifyCollectionChanged).CollectionChanged += OnContextMenuItemsChanged;
+
+ PrepareMenuItems();
+ }
+
+ protected override void OnApplyTemplate()
+ {
+ _root = GetTemplateChild("Root") as Grid;
+ _menuFlyout = GetTemplateChild("Flyout") as MenuFlyout;
+
+ PrepareMenuItems();
+ }
+
+ private void OnContextMenuItemsChanged(object sender, NotifyCollectionChangedEventArgs args)
+ {
+ if (_flyout == null) return;
+
+ var contextMenu = _flyout.ContextMenu;
+ if (contextMenu == null) return;
+
+ var addedItems = args.NewItems.Cast().ToList();
+ var removedItems = args.NewItems.Cast().ToList();
+
+ if (removedItems != null)
+ {
+ foreach (var item in removedItems)
+ {
+ _menuFlyout.Items.Remove(item);
+ }
+ }
+
+ foreach (var item in addedItems)
+ {
+ _menuFlyout.Items.Add(item);
+ }
+ }
+
+ private void PrepareMenuItems()
+ {
+ if (_menuFlyout == null) return;
+ if (_flyout == null) return;
+
+ var contextMenu = _flyout.ContextMenu;
+ if (contextMenu == null) return;
+
+ _menuFlyout.Items.Clear();
+
+ var items = contextMenu.MenuItems;
+ foreach (var item in items)
+ {
+ _menuFlyout.Items.Add(item);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.xaml b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.xaml
similarity index 78%
rename from src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.xaml
rename to src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.xaml
index 87cf47d..c891b96 100644
--- a/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.xaml
+++ b/src/NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.xaml
@@ -2,10 +2,10 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:NotificationFlyout.Uwp.UI.Controls">
-
-
+
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/Properties/AssemblyInfo.cs b/src/NotificationFlyout.Uwp.UI.Controls/Properties/AssemblyInfo.cs
index f37014a..570c48b 100644
--- a/src/NotificationFlyout.Uwp.UI.Controls/Properties/AssemblyInfo.cs
+++ b/src/NotificationFlyout.Uwp.UI.Controls/Properties/AssemblyInfo.cs
@@ -13,4 +13,4 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
-[assembly: InternalsVisibleTo("NotificationFlyout.Wpf.UI.Controls")]
+[assembly: InternalsVisibleTo("NotificationFlyout.Wpf.UI.Controls")]
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI.Controls/Themes/Generic.xaml b/src/NotificationFlyout.Uwp.UI.Controls/Themes/Generic.xaml
index 2052801..db4726b 100644
--- a/src/NotificationFlyout.Uwp.UI.Controls/Themes/Generic.xaml
+++ b/src/NotificationFlyout.Uwp.UI.Controls/Themes/Generic.xaml
@@ -2,6 +2,6 @@
-
+
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI/Extensions/ExecutionMode.cs b/src/NotificationFlyout.Uwp.UI/Extensions/ExecutionMode.cs
index de3d269..f19d8fc 100644
--- a/src/NotificationFlyout.Uwp.UI/Extensions/ExecutionMode.cs
+++ b/src/NotificationFlyout.Uwp.UI/Extensions/ExecutionMode.cs
@@ -12,4 +12,4 @@ namespace NotificationFlyout.Uwp.UI.Extensions
return result != 15700;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI/Extensions/ImageSourceExtensions.cs b/src/NotificationFlyout.Uwp.UI/Extensions/ImageSourceExtensions.cs
index ae9884d..6ff6806 100644
--- a/src/NotificationFlyout.Uwp.UI/Extensions/ImageSourceExtensions.cs
+++ b/src/NotificationFlyout.Uwp.UI/Extensions/ImageSourceExtensions.cs
@@ -2,11 +2,9 @@
using System;
using System.Drawing;
using System.IO;
+using System.Threading.Tasks;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
-using System.Threading.Tasks;
-using System.Runtime.InteropServices;
-using System.Text;
namespace NotificationFlyout.Uwp.UI.Extensions
{
@@ -27,8 +25,7 @@ namespace NotificationFlyout.Uwp.UI.Extensions
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(bitmapImage.UriSource);
using var stream = await storageFile.OpenStreamForReadAsync();
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
-
- }
+ }
}
private enum SystemMetricFlag : int
@@ -39,4 +36,4 @@ namespace NotificationFlyout.Uwp.UI.Extensions
SM_CYSMICON = 50
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Uwp.UI/INotificationFlyoutApplication.cs b/src/NotificationFlyout.Uwp.UI/INotificationFlyoutApplication.cs
index 5e4481b..ff99fec 100644
--- a/src/NotificationFlyout.Uwp.UI/INotificationFlyoutApplication.cs
+++ b/src/NotificationFlyout.Uwp.UI/INotificationFlyoutApplication.cs
@@ -8,4 +8,4 @@ namespace NotificationFlyout.Uwp.UI
void OpenAsWindow() where TUIElement : UIElement;
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutApplication.cs b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutApplication.cs
index c8afc3d..94d4625 100644
--- a/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutApplication.cs
+++ b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutApplication.cs
@@ -1,5 +1,4 @@
using NotificationFlyout.Uwp.UI;
-using System;
using System.Windows;
using System.Windows.Markup;
@@ -13,23 +12,18 @@ namespace NotificationFlyout.Wpf.UI.Controls
typeof(Uwp.UI.Controls.NotificationFlyout), typeof(NotificationFlyoutApplication),
new PropertyMetadata(null, OnFlyoutPropertyChanged));
- private static NotificationFlyoutApplication _instance;
- private readonly ContextMenuXamlHost _contextMenuXamlHost;
- private readonly NotificationFlyoutXamlHost _notificationFlyoutXamlHost;
+ private static NotificationFlyoutApplication _application;
+ private NotificationFlyoutXamlHost _notificationFlyoutXamlHost;
public NotificationFlyoutApplication()
{
- _instance = this;
+ _application = this;
+ Uwp.UI.Controls.NotificationFlyout.SetApplication(this);
- _notificationFlyoutXamlHost = new NotificationFlyoutXamlHost();
- _notificationFlyoutXamlHost.ContextMenuRequested += OnContextMenuRequested;
- _notificationFlyoutXamlHost.Show();
-
- _contextMenuXamlHost = new ContextMenuXamlHost();
- _contextMenuXamlHost.Show();
+ PrepareFlyoutHost();
}
- public static INotificationFlyoutApplication Current => _instance;
+ public static INotificationFlyoutApplication Current => _application;
public Uwp.UI.Controls.NotificationFlyout Flyout
{
@@ -37,16 +31,9 @@ namespace NotificationFlyout.Wpf.UI.Controls
set => SetValue(FlyoutProperty, value);
}
- public void Exit()
- {
- _contextMenuXamlHost.Close();
- _notificationFlyoutXamlHost.Close();
- }
+ public void Exit() => _notificationFlyoutXamlHost.Close();
- public void HideFlyout()
- {
- _notificationFlyoutXamlHost.HideFlyout();
- }
+ public void HideFlyout() => _notificationFlyoutXamlHost.HideFlyout();
public void OpenAsWindow() where TUIElement : Windows.UI.Xaml.UIElement
{
@@ -54,10 +41,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
window.Show();
}
- public void ShowFlyout()
- {
- _notificationFlyoutXamlHost.ShowFlyout();
- }
+ public void ShowFlyout() => _notificationFlyoutXamlHost.ShowFlyout();
private static void OnFlyoutPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
@@ -65,17 +49,12 @@ namespace NotificationFlyout.Wpf.UI.Controls
sender?.OnFlyoutPropertyChanged();
}
- private void OnContextMenuRequested(object sender, EventArgs args)
- {
- _contextMenuXamlHost?.ShowContextMenuFlyout();
- }
+ private void OnFlyoutPropertyChanged() => _notificationFlyoutXamlHost.SetOwningFlyout(Flyout);
- private void OnFlyoutPropertyChanged()
+ private void PrepareFlyoutHost()
{
- _notificationFlyoutXamlHost?.SetFlyout(Flyout);
- _contextMenuXamlHost?.SetFlyout(Flyout);
-
- Uwp.UI.Controls.NotificationFlyout.SetApplication(this);
+ _notificationFlyoutXamlHost = new NotificationFlyoutXamlHost();
+ _notificationFlyoutXamlHost.Show();
}
}
}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuXamlHost.cs b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuXamlHost.cs
new file mode 100644
index 0000000..a1c6c3e
--- /dev/null
+++ b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuXamlHost.cs
@@ -0,0 +1,44 @@
+using NotificationFlyout.Uwp.UI.Controls;
+using NotificationFlyout.Wpf.UI.Extensions;
+using NotificationFlyout.Wpf.UI.Helpers;
+using System;
+
+namespace NotificationFlyout.Wpf.UI.Controls
+{
+ internal class NotificationFlyoutContextMenuXamlHost : TransparentXamlHost
+ {
+ public NotificationFlyoutContextMenuXamlHost() => Topmost = true;
+
+ internal void SetOwningFlyout(Uwp.UI.Controls.NotificationFlyout flyout)
+ {
+ var content = GetHostContent();
+ if (content != null)
+ {
+ content.SetOwningFlyout(flyout);
+ }
+ }
+
+ internal void ShowContextMenuFlyout()
+ {
+ var position = CursorHelper.GetPhysicalCursorPos();
+ this.SetWindowPosition(position.y, position.x, WindowSize, WindowSize);
+
+ var flyoutHost = GetHostContent();
+ if (flyoutHost != null)
+ {
+ flyoutHost.ShowFlyout();
+ }
+
+ Activate();
+ }
+
+ protected override void OnDeactivated(EventArgs args)
+ {
+ var flyoutHost = GetHostContent();
+ if (flyoutHost != null)
+ {
+ flyoutHost.HideFlyout();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/NotificationFlyoutXamlHost.cs b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs
similarity index 70%
rename from src/NotificationFlyout.Wpf.UI.Controls/XamlHost/NotificationFlyoutXamlHost.cs
rename to src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs
index 378926f..0186d34 100644
--- a/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/NotificationFlyoutXamlHost.cs
+++ b/src/NotificationFlyout.Wpf.UI.Controls/NotificationFlyout/NotificationFlyoutXamlHost.cs
@@ -3,6 +3,7 @@ using NotificationFlyout.Uwp.UI.Extensions;
using NotificationFlyout.Wpf.UI.Extensions;
using NotificationFlyout.Wpf.UI.Helpers;
using System;
+using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Windows.UI.Xaml.Controls.Primitives;
@@ -13,33 +14,12 @@ namespace NotificationFlyout.Wpf.UI.Controls
{
private const string ShellTrayHandleName = "Shell_TrayWnd";
+ private NotificationFlyoutContextMenuXamlHost _contextMenuXamlHost;
private Uwp.UI.Controls.NotificationFlyout _flyout;
-
private NotificationIconHelper _notificationIconHelper;
private SystemPersonalisationHelper _systemPersonalisationHelper;
private TaskbarHelper _taskbarHelper;
- internal event EventHandler ContextMenuRequested;
-
- public void SetFlyout(Uwp.UI.Controls.NotificationFlyout flyout)
- {
- if (_flyout != null)
- {
- _flyout.ContentChanged -= OnFlyoutContentChanged;
- _flyout.IconSourceChanged -= OnFlyoutIconSourceChanged;
- _flyout.RequestedThemeChanged -= OnFlyoutIconSourceChanged;
- }
-
- _flyout = flyout;
- _flyout.ContentChanged += OnFlyoutContentChanged;
- _flyout.IconSourceChanged += OnFlyoutIconSourceChanged;
- _flyout.RequestedThemeChanged += OnFlyoutRequestedThemeChanged;
-
- UpdateIcons();
- UpdateFlyoutContent();
- UpdateRequestedTheme();
- }
-
internal void HideFlyout()
{
var flyoutHost = GetHostContent();
@@ -49,10 +29,32 @@ namespace NotificationFlyout.Wpf.UI.Controls
}
}
+ internal void SetOwningFlyout(Uwp.UI.Controls.NotificationFlyout flyout)
+ {
+ if (_flyout != null)
+ {
+ _flyout.IconSourceChanged -= OnIconSourceChanged;
+ _flyout.ContextMenuChanged -= OnContextMenuChanged;
+ }
+
+ _flyout = flyout;
+ _flyout.IconSourceChanged += OnIconSourceChanged;
+ _flyout.ContextMenuChanged += OnContextMenuChanged;
+
+ var content = GetHostContent();
+ if (content != null)
+ {
+ content.SetOwningFlyout(_flyout);
+ }
+
+ UpdateIcons();
+ PrepareContextMenu();
+ }
+
internal void ShowFlyout()
{
- var flyoutHost = GetHostContent();
- if (flyoutHost != null)
+ var content = GetHostContent();
+ if (content != null)
{
var taskbarState = _taskbarHelper.GetCurrentState();
var flyoutPlacement = taskbarState.Position switch
@@ -65,10 +67,18 @@ namespace NotificationFlyout.Wpf.UI.Controls
};
Activate();
- flyoutHost.ShowFlyout(flyoutPlacement);
+ content.ShowFlyout(flyoutPlacement);
}
}
+ protected override void OnClosed(EventArgs args)
+ {
+ _notificationIconHelper.Dispose();
+
+ if (_contextMenuXamlHost == null) return;
+ _contextMenuXamlHost.Close();
+ }
+
protected override void OnContentLoaded()
{
PrepareNotificationIcon();
@@ -76,25 +86,9 @@ namespace NotificationFlyout.Wpf.UI.Controls
UpdateWindow();
}
- protected override void OnDeactivated(EventArgs args)
- {
- HideFlyout();
- }
+ protected override void OnDeactivated(EventArgs args) => HideFlyout();
- private void OnFlyoutContentChanged(object sender, EventArgs args)
- {
- UpdateFlyoutContent();
- }
-
- private void OnFlyoutIconSourceChanged(object sender, EventArgs args)
- {
- UpdateIcons();
- }
-
- private void OnFlyoutRequestedThemeChanged(object sender, EventArgs args)
- {
- UpdateRequestedTheme();
- }
+ private void OnContextMenuChanged(object sender, EventArgs args) => PrepareContextMenu();
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
{
@@ -105,20 +99,35 @@ namespace NotificationFlyout.Wpf.UI.Controls
if (args.MouseButton == MouseButton.Right)
{
- ContextMenuRequested?.Invoke(this, EventArgs.Empty);
+ ShowContextMenuFlyout();
}
}
- private void OnTaskbarChanged(object sender, EventArgs args)
- {
- UpdateWindow();
- }
+ private void OnIconSourceChanged(object sender, EventArgs args) => UpdateIcons();
- private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args)
- {
- UpdateIcons();
- }
+ private void OnTaskbarChanged(object sender, EventArgs args) => UpdateWindow();
+ private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args) => UpdateIcons();
+
+ private void PrepareContextMenu()
+ {
+ if (_contextMenuXamlHost != null)
+ {
+ _contextMenuXamlHost.Close();
+ _contextMenuXamlHost = null;
+ }
+
+ var contextMenu = _flyout.ContextMenu;
+ if (contextMenu == null) return;
+
+ if (_contextMenuXamlHost == null)
+ {
+ _contextMenuXamlHost = new NotificationFlyoutContextMenuXamlHost();
+ _contextMenuXamlHost.Show();
+ }
+
+ _contextMenuXamlHost.SetOwningFlyout(_flyout);
+ }
private void PrepareNotificationIcon()
{
_notificationIconHelper = NotificationIconHelper.Create(this);
@@ -136,59 +145,30 @@ namespace NotificationFlyout.Wpf.UI.Controls
_taskbarHelper.TaskbarChanged += OnTaskbarChanged;
}
- protected override void OnClosed(EventArgs args)
+ private void ShowContextMenuFlyout()
{
- _notificationIconHelper.Dispose();
+ if (_contextMenuXamlHost == null) return;
+ _contextMenuXamlHost.ShowContextMenuFlyout();
}
-
- private void UpdateFlyoutContent()
- {
- if (_flyout == null) return;
-
- var content = _flyout.Content;
- if (content == null) return;
-
- var flyoutHost = GetHostContent();
- if (flyoutHost != null)
- {
- flyoutHost.Content = content;
- }
- }
-
private async void UpdateIcons()
{
if (!IsLoaded) return;
-
if (_flyout == null) return;
- var _defaultIconSource = _flyout.IconSource;
- var _lightIconSource = _flyout.LightIconSource;
+ var iconSource = _flyout.IconSource;
+ var lightIconSource = _flyout.LightIconSource;
var shellTrayHandle = WindowHelper.GetHandle(ShellTrayHandleName);
if (shellTrayHandle == null) return;
+ var desiredIconSource = _systemPersonalisationHelper.Theme == SystemTheme.Dark ? iconSource : lightIconSource;
+ if (desiredIconSource == null) return;
+
var dpi = WindowHelper.GetDpi(shellTrayHandle);
-
- var iconSource = _systemPersonalisationHelper.Theme == SystemTheme.Dark ? _defaultIconSource : _lightIconSource;
- if (iconSource == null) return;
-
- using var icon = await iconSource.ConvertToIconAsync(dpi);
+ using var icon = await desiredIconSource.ConvertToIconAsync(dpi);
_notificationIconHelper.SetIcon(icon.Handle);
}
- private void UpdateRequestedTheme()
- {
- if (_flyout == null) return;
-
- var requestedTheme = _flyout.RequestedTheme;
-
- var flyoutHost = GetHostContent();
- if (flyoutHost != null)
- {
- flyoutHost.RequestedTheme = requestedTheme;
- }
- }
-
private void UpdateWindow()
{
if (!IsLoaded) return;
diff --git a/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/NotificationFlyoutContextMenuXamlHost.cs b/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/NotificationFlyoutContextMenuXamlHost.cs
deleted file mode 100644
index 52a36b0..0000000
--- a/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/NotificationFlyoutContextMenuXamlHost.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-using NotificationFlyout.Uwp.UI.Controls;
-using NotificationFlyout.Wpf.UI.Extensions;
-using NotificationFlyout.Wpf.UI.Helpers;
-using System;
-using System.Collections.Generic;
-using Windows.UI.Xaml.Controls;
-
-namespace NotificationFlyout.Wpf.UI.Controls
-{
- internal class ContextMenuXamlHost : TransparentXamlHost
- {
- private Uwp.UI.Controls.NotificationFlyout _flyout;
-
- public ContextMenuXamlHost()
- {
- Topmost = true;
- }
-
- public void SetFlyout(Uwp.UI.Controls.NotificationFlyout flyout)
- {
- if (_flyout != null)
- {
- _flyout.MenuItemsChanged -= OnContextMenuItemsChanged;
- }
-
- _flyout = flyout;
- UpdateMenuItems();
- }
-
- public void ShowContextMenuFlyout()
- {
- var position = CursorHelper.GetPhysicalCursorPos();
- this.SetWindowPosition(position.y, position.x, WindowSize, WindowSize);
-
- var flyoutHost = GetHostContent();
- if (flyoutHost != null)
- {
- flyoutHost.ShowFlyout();
- }
-
- Activate();
- }
-
- protected override void OnContentLoaded()
- {
- UpdateMenuItems();
- }
-
- protected override void OnDeactivated(EventArgs args)
- {
- var flyoutHost = GetHostContent();
- if (flyoutHost != null)
- {
- flyoutHost.HideFlyout();
- }
- }
-
- private void OnContextMenuItemsChanged(object sender, NotificationFlyoutMenuItemsChangedEventArgs args)
- {
- UpdateMenuItems(args.AddedItems, args.RemovedItems);
- }
-
- private void UpdateMenuItems()
- {
- if (_flyout == null) return;
- UpdateMenuItems(_flyout.ContextMenuItems);
- }
-
- private void UpdateMenuItems(IList addedItems, IList removedItems = default)
- {
- var flyoutHost = GetHostContent();
- if (flyoutHost != null)
- {
- flyoutHost.SetMenuItems(addedItems, removedItems);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/XamlHost.cs b/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/XamlHost.cs
index 6f84fea..6e0c2fa 100644
--- a/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/XamlHost.cs
+++ b/src/NotificationFlyout.Wpf.UI.Controls/XamlHost/XamlHost.cs
@@ -1,5 +1,4 @@
using Microsoft.Toolkit.Wpf.UI.XamlHost;
-using NotificationFlyout.Wpf.UI.Extensions;
using System;
using System.Windows;
@@ -16,7 +15,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
ContentRendered += OnContentRendered;
}
- protected TXamlContent GetHostContent()
+ internal TXamlContent GetHostContent()
{
if (_xamlHost == null) return null;
return _xamlHost.GetUwpInternalObject() as TXamlContent;
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/ImageSourceExtensions.cs b/src/NotificationFlyout.Wpf.UI/Extensions/ImageSourceExtensions.cs
index 0f8e591..f6feae7 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/ImageSourceExtensions.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/ImageSourceExtensions.cs
@@ -28,4 +28,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
SM_CYSMICON = 50
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemExtensions.cs b/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemExtensions.cs
index 50d2dae..18afe5b 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemExtensions.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemExtensions.cs
@@ -10,4 +10,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return operatingSystem.Version.Build > (int)version;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemVersion.cs b/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemVersion.cs
index 43b24e5..35de1b3 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemVersion.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/OperatingSystemVersion.cs
@@ -11,4 +11,4 @@
Windows10_1809 = 17763,
Windows10_1903 = 18362
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/RECTExtensions.cs b/src/NotificationFlyout.Wpf.UI/Extensions/RECTExtensions.cs
index 8ad0dc7..6b8c2f7 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/RECTExtensions.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/RECTExtensions.cs
@@ -12,4 +12,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs b/src/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs
index 1962139..cfdd6e9 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/RegistryKeyExtensions.cs
@@ -9,4 +9,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return string.IsNullOrWhiteSpace(valueName) ? defaultValue : key.GetValue(valueName, defaultValue) is T value ? value : defaultValue;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/VisualExtensions.cs b/src/NotificationFlyout.Wpf.UI/Extensions/VisualExtensions.cs
index 58b3dc5..79331c2 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/VisualExtensions.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/VisualExtensions.cs
@@ -36,4 +36,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return false;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Extensions/WindowExtensions.cs b/src/NotificationFlyout.Wpf.UI/Extensions/WindowExtensions.cs
index c1a04a1..7b4067f 100644
--- a/src/NotificationFlyout.Wpf.UI/Extensions/WindowExtensions.cs
+++ b/src/NotificationFlyout.Wpf.UI/Extensions/WindowExtensions.cs
@@ -18,7 +18,7 @@ namespace NotificationFlyout.Wpf.UI.Extensions
SWP_NOACTIVATE = 0x0010,
WS_EX_NOACTIVATE = 0x08000000,
SWP_SHOWWINDOW = 0x0040,
- WS_EX_APPWINDOW = 0x00040000,
+ WS_EX_APPWINDOW = 0x00040000,
WS_EX_TOOLWINDOW = 0x00000080
}
@@ -44,4 +44,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
PInvoke.SetWindowPos((HWND)window.GetHandle(), (HWND)IntPtr.Zero, (int)left, (int)top, (int)width, (int)height, (uint)WindowFlag.SWP_NOSIZE | (uint)WindowFlag.SWP_NOZORDER | (uint)WindowFlag.SWP_NOACTIVATE);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/CursorHelper.cs b/src/NotificationFlyout.Wpf.UI/Helpers/CursorHelper.cs
index 536041f..dd6e39d 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/CursorHelper.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/CursorHelper.cs
@@ -6,8 +6,8 @@ namespace NotificationFlyout.Wpf.UI.Helpers
{
public static POINT GetPhysicalCursorPos()
{
- PInvoke.GetPhysicalCursorPos(out POINT point);
+ PInvoke.GetPhysicalCursorPos(out var point);
return point;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs b/src/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs
index 52c8cb7..7e188f1 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/NotificationIconHelper.cs
@@ -27,7 +27,6 @@ namespace NotificationFlyout.Wpf.UI.Helpers
CreateNotificationIcon();
}
-
~NotificationIconHelper()
{
Dispose(false);
@@ -147,9 +146,11 @@ namespace NotificationFlyout.Wpf.UI.Helpers
case (uint)WndProcMessages.WM_LBUTTONUP:
InvokeIconInvoked(MouseButton.Left);
break;
+
case (uint)WndProcMessages.WM_MBUTTONUP:
InvokeIconInvoked(MouseButton.Middle);
break;
+
case (uint)WndProcMessages.WM_RBUTTONUP:
InvokeIconInvoked(MouseButton.Right);
break;
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/SystemInformationHelper.cs b/src/NotificationFlyout.Wpf.UI/Helpers/SystemInformationHelper.cs
index cde40e5..26ddde2 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/SystemInformationHelper.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/SystemInformationHelper.cs
@@ -41,4 +41,4 @@ namespace NotificationFlyout.Wpf.UI.Helpers
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool SystemParametersInfo(int nAction, int nParam, ref RECT rc, int nUpdate);
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/SystemPersonalisationHelper.cs b/src/NotificationFlyout.Wpf.UI/Helpers/SystemPersonalisationHelper.cs
index bb7631d..e96784f 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/SystemPersonalisationHelper.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/SystemPersonalisationHelper.cs
@@ -74,4 +74,4 @@ namespace NotificationFlyout.Wpf.UI.Helpers
return DefWindowProcW(hwnd, (uint)msg, wParam, (lParam));
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs b/src/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs
index 251bb9a..f11aaa7 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/SystemTheme.cs
@@ -5,4 +5,4 @@
Dark,
Light,
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs b/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs
index 859bceb..2cb4f7c 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarHelper.cs
@@ -115,4 +115,4 @@ namespace NotificationFlyout.Wpf.UI.Helpers
public int lParam;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarPosition.cs b/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarPosition.cs
index 6cb41bf..9353f4e 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarPosition.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/TaskbarPosition.cs
@@ -1,6 +1,5 @@
namespace NotificationFlyout.Wpf.UI
{
-
public enum TaskbarPosition
{
Left = 0,
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/ThemeChangedEventArgs.cs b/src/NotificationFlyout.Wpf.UI/Helpers/ThemeChangedEventArgs.cs
index 8a14153..94455c5 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/ThemeChangedEventArgs.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/ThemeChangedEventArgs.cs
@@ -13,6 +13,5 @@ namespace NotificationFlyout.Wpf.UI.Helpers
public SystemTheme Theme { get; private set; }
public bool IsColorPrevalence { get; private set; }
-
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Helpers/WindowHelper.cs b/src/NotificationFlyout.Wpf.UI/Helpers/WindowHelper.cs
index 03ff11b..b0113ef 100644
--- a/src/NotificationFlyout.Wpf.UI/Helpers/WindowHelper.cs
+++ b/src/NotificationFlyout.Wpf.UI/Helpers/WindowHelper.cs
@@ -1,5 +1,5 @@
-using System;
-using Microsoft.Windows.Sdk;
+using Microsoft.Windows.Sdk;
+using System;
namespace NotificationFlyout.Wpf.UI.Helpers
{
@@ -15,4 +15,4 @@ namespace NotificationFlyout.Wpf.UI.Helpers
return PInvoke.GetDpiForWindow((HWND)handle);
}
}
-}
+}
\ No newline at end of file
diff --git a/src/NotificationFlyout.Wpf.UI/Screen.cs b/src/NotificationFlyout.Wpf.UI/Screen.cs
index f08f35b..345ab03 100644
--- a/src/NotificationFlyout.Wpf.UI/Screen.cs
+++ b/src/NotificationFlyout.Wpf.UI/Screen.cs
@@ -32,7 +32,7 @@ namespace NotificationFlyout.Wpf.UI
{
var monitorData = GetMonitorData(monitorHandle);
- Bounds = new Rect(monitorData.MonitorRect.left, monitorData.MonitorRect.top, monitorData.MonitorRect.right - monitorData.MonitorRect.left, monitorData.MonitorRect.bottom - monitorData.MonitorRect.top);
+ Bounds = new Rect(monitorData.MonitorRect.left, monitorData.MonitorRect.top, monitorData.MonitorRect.right - monitorData.MonitorRect.left, monitorData.MonitorRect.bottom - monitorData.MonitorRect.top);
Primary = (monitorData.Flags & (int)MonitorFlag.MONITOR_DEFAULTTOPRIMARY) != 0;
DeviceName = monitorData.DeviceName;
}
@@ -62,14 +62,8 @@ namespace NotificationFlyout.Wpf.UI
public override bool Equals(object obj)
{
- if (obj is Screen monitor)
- {
- if (_monitorHandle == monitor._monitorHandle)
- {
- return true;
- }
- }
- return false;
+ if (obj is not Screen monitor) return false;
+ return _monitorHandle == monitor._monitorHandle;
}
public override int GetHashCode()