refactoring for the next stage

This commit is contained in:
Daniel Clark
2021-02-12 23:23:41 +00:00
parent e459a85f02
commit 84afcf0be3
50 changed files with 389 additions and 460 deletions
@@ -3,4 +3,4 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources />
</Application>
</Application>
@@ -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
{
}
}
}
@@ -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)
)]
)]
@@ -12,11 +12,11 @@ namespace NotificationFlyoutSample.Host
{
var app = new App();
new NotificationFlyoutApplication
{
{
Flyout = new Shell()
};
app.Run();
}
}
}
}
}
-32
View File
@@ -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
+1 -1
View File
@@ -6,4 +6,4 @@
<xamlhost:XamlApplication.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" Version="Latest" />
</xamlhost:XamlApplication.Resources>
</xamlhost:XamlApplication>
</xamlhost:XamlApplication>
+1 -1
View File
@@ -9,4 +9,4 @@ namespace NotificationFlyoutSample
Initialize();
}
}
}
}
@@ -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")]
@@ -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
<Type Name="App1.MyClass" Dynamic="Required All"/>
<Type Name="App1.MyClass" Dynamic="Required All" />
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
@@ -22,10 +22,7 @@
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All" />
<!-- Add your application specific runtime directives here. -->
</Application>
</Directives>
+10 -5
View File
@@ -6,9 +6,11 @@
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
IconSource="/Assets/Icon.ico"
LightIconSource="/Assets/Icon-Light.ico">
<controls:NotificationFlyout.ContextMenuItems>
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="Close" />
</controls:NotificationFlyout.ContextMenuItems>
<controls:NotificationFlyout.ContextMenu>
<controls:NotificationFlyoutContextMenu>
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="Close" />
</controls:NotificationFlyoutContextMenu>
</controls:NotificationFlyout.ContextMenu>
<StackPanel Margin="24">
<ComboBox
x:Name="Theme"
@@ -44,7 +46,10 @@
IsIndeterminate="True"
ShowError="False"
ShowPaused="False" />
<Button Margin="0,0,0,8" Content="Open window" Click="Button_Click" />
<Button
Margin="0,0,0,8"
Click="Button_Click"
Content="Open window" />
<Slider Margin="0,0,0,8" />
<TextBox Margin="0,0,0,8" />
<CalendarView Margin="0,0,0,8" />
@@ -83,4 +88,4 @@
</StackPanel>
<muxc:RatingControl AutomationProperties.Name="RatingControl with placeholder" PlaceholderValue="0" />
</StackPanel>
</controls:NotificationFlyout>
</controls:NotificationFlyout>
@@ -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<WindowContent>();
}
}
}
}
@@ -24,4 +24,4 @@
</muxc:NavigationView.MenuItems>
<Frame x:Name="contentFrame" />
</muxc:NavigationView>
</UserControl>
</UserControl>
@@ -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();
}
}
}
}
@@ -13,7 +13,7 @@
<Version>1.0.0</Version> </PropertyGroup>
<ItemGroup>
<Page Include="NotificationFlyout\ContextMenuFlyoutHost.xaml">
<Page Include="NotificationFlyout\NotificationFlyoutContextMenuFlyoutHost.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@@ -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<MenuFlyoutItemBase> addedItems, IList<MenuFlyoutItemBase> 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);
}
}
}
}
@@ -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<MenuFlyoutItemBase>), typeof(NotificationFlyout),
new PropertyMetadata(null));
public NotificationFlyout()
{
ContextMenuItems = new ObservableCollection<MenuFlyoutItemBase>();
(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<NotificationFlyoutMenuItemsChangedEventArgs> MenuItemsChanged;
internal event EventHandler RequestedThemeChanged;
public UIElement Content
{
get => (UIElement)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public IList<MenuFlyoutItemBase> ContextMenuItems
public NotificationFlyoutContextMenu ContextMenu
{
get => (IList<MenuFlyoutItemBase>)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<MenuFlyoutItemBase>().ToList();
var removedItems = args.NewItems.Cast<MenuFlyoutItemBase>().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<MenuFlyoutItemBase> addedItems, IList<MenuFlyoutItemBase> removedItems)
{
AddedItems = addedItems;
RemovedItems = removedItems;
}
public IList<MenuFlyoutItemBase> AddedItems { get; private set; }
public IList<MenuFlyoutItemBase> RemovedItems { get; private set; }
}
}
}
@@ -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<MenuFlyoutItemBase>), typeof(NotificationFlyout),
new PropertyMetadata(null));
public NotificationFlyoutContextMenu() => MenuItems = new ObservableCollection<MenuFlyoutItemBase>();
public IList<MenuFlyoutItemBase> MenuItems
{
get => (IList<MenuFlyoutItemBase>)GetValue(MenuItemsProperty);
set => SetValue(MenuItemsProperty, value);
}
}
}
@@ -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<MenuFlyoutItemBase>().ToList();
var removedItems = args.NewItems.Cast<MenuFlyoutItemBase>().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);
}
}
}
}
@@ -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">
<Style TargetType="controls:ContextMenuFlyoutHost">
<Style TargetType="controls:NotificationFlyoutContextMenuFlyoutHost">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:ContextMenuFlyoutHost">
<ControlTemplate TargetType="controls:NotificationFlyoutContextMenuFlyoutHost">
<Grid x:Name="Root">
<FlyoutBase.AttachedFlyout>
<MenuFlyout x:Name="Flyout" />
@@ -2,6 +2,7 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
namespace NotificationFlyout.Uwp.UI.Controls
@@ -17,9 +18,26 @@ namespace NotificationFlyout.Uwp.UI.Controls
private string _placement;
private Grid _root;
public NotificationFlyoutHost()
public NotificationFlyoutHost() => DefaultStyleKey = typeof(NotificationFlyoutHost);
internal void SetOwningFlyout(NotificationFlyout flyout)
{
DefaultStyleKey = typeof(NotificationFlyoutHost);
BindingOperations.SetBinding(this, ContentProperty,
new Binding
{
Source = flyout,
Path =
new PropertyPath(nameof(Content)),
Mode = BindingMode.TwoWay
});
BindingOperations.SetBinding(this, RequestedThemeProperty,
new Binding
{
Source = flyout,
Path = new PropertyPath(nameof(RequestedTheme)),
Mode = BindingMode.TwoWay
});
}
public UIElement Content
@@ -54,7 +72,7 @@ namespace NotificationFlyout.Uwp.UI.Controls
{
Placement = placementMode,
ShowMode = FlyoutShowMode.Standard,
});
});
}
protected override void OnApplyTemplate()
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Controls;
namespace NotificationFlyout.Uwp.UI.Controls
{
internal class NotificationFlyoutMenuItemsChangedEventArgs : EventArgs
{
public NotificationFlyoutMenuItemsChangedEventArgs(IList<MenuFlyoutItemBase> addedItems, IList<MenuFlyoutItemBase> removedItems)
{
AddedItems = addedItems;
RemovedItems = removedItems;
}
public IList<MenuFlyoutItemBase> AddedItems { get; private set; }
public IList<MenuFlyoutItemBase> RemovedItems { get; private set; }
}
}
@@ -4,9 +4,6 @@ namespace NotificationFlyout.Uwp.UI.Controls
{
public class NotificationFlyoutPresenter : ContentControl
{
public NotificationFlyoutPresenter()
{
DefaultStyleKey = typeof(NotificationFlyoutPresenter);
}
public NotificationFlyoutPresenter() => DefaultStyleKey = typeof(NotificationFlyoutPresenter);
}
}
@@ -76,4 +76,4 @@
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</ResourceDictionary>
@@ -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")]
@@ -2,6 +2,6 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutHost.xaml" />
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutPresenter.xaml" />
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/ContextMenuFlyoutHost.xaml" />
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutContextMenuFlyoutHost.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
@@ -12,4 +12,4 @@ namespace NotificationFlyout.Uwp.UI.Extensions
return result != 15700;
}
}
}
}
@@ -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
}
}
}
}
@@ -8,4 +8,4 @@ namespace NotificationFlyout.Uwp.UI
void OpenAsWindow<TUIElement>() where TUIElement : UIElement;
}
}
}
@@ -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<TUIElement>() 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();
}
}
}
@@ -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<NotificationFlyoutContextMenuFlyoutHost>
{
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();
}
}
}
}
@@ -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;
@@ -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<ContextMenuFlyoutHost>
{
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<MenuFlyoutItemBase> addedItems, IList<MenuFlyoutItemBase> removedItems = default)
{
var flyoutHost = GetHostContent();
if (flyoutHost != null)
{
flyoutHost.SetMenuItems(addedItems, removedItems);
}
}
}
}
@@ -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;
@@ -28,4 +28,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
SM_CYSMICON = 50
}
}
}
}
@@ -10,4 +10,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return operatingSystem.Version.Build > (int)version;
}
}
}
}
@@ -11,4 +11,4 @@
Windows10_1809 = 17763,
Windows10_1903 = 18362
}
}
}
@@ -12,4 +12,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
}
}
}
@@ -9,4 +9,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return string.IsNullOrWhiteSpace(valueName) ? defaultValue : key.GetValue(valueName, defaultValue) is T value ? value : defaultValue;
}
}
}
}
@@ -36,4 +36,4 @@ namespace NotificationFlyout.Wpf.UI.Extensions
return false;
}
}
}
}
@@ -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);
}
}
}
}
@@ -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;
}
}
}
}
@@ -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;
@@ -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);
}
}
}
@@ -74,4 +74,4 @@ namespace NotificationFlyout.Wpf.UI.Helpers
return DefWindowProcW(hwnd, (uint)msg, wParam, (lParam));
}
}
}
}
@@ -5,4 +5,4 @@
Dark,
Light,
}
}
}
@@ -115,4 +115,4 @@ namespace NotificationFlyout.Wpf.UI.Helpers
public int lParam;
}
}
}
}
@@ -1,6 +1,5 @@
namespace NotificationFlyout.Wpf.UI
{
public enum TaskbarPosition
{
Left = 0,
@@ -13,6 +13,5 @@ namespace NotificationFlyout.Wpf.UI.Helpers
public SystemTheme Theme { get; private set; }
public bool IsColorPrevalence { get; private set; }
}
}
}
@@ -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);
}
}
}
}
+3 -9
View File
@@ -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()