Added API for closing FlyoutApplication from the Flyout control in two seperate projects.
This commit is contained in:
@@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotificationFlyout.Wpf.UI",
|
|||||||
EndProject
|
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}"
|
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
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotificationFlyout.Uwp.UI", "..\..\src\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj", "{ADE190A2-F751-4836-B8F4-BF56694A4B3F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -139,6 +141,26 @@ Global
|
|||||||
{094A2030-C430-490B-AB26-205385A0D4BF}.Release|x64.Build.0 = Release|x64
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{094A2030-C430-490B-AB26-205385A0D4BF}.Release|x86.Build.0 = Release|Any CPU
|
{094A2030-C430-490B-AB26-205385A0D4BF}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|ARM.Build.0 = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|ARM64.Build.0 = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|x64.Build.0 = Release|x64
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{ADE190A2-F751-4836-B8F4-BF56694A4B3F}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
+4
@@ -169,6 +169,10 @@
|
|||||||
<Project>{95f851e4-87a5-4bb7-953e-c0fe3b306f0e}</Project>
|
<Project>{95f851e4-87a5-4bb7-953e-c0fe3b306f0e}</Project>
|
||||||
<Name>NotificationFlyout.Uwp.UI.Controls</Name>
|
<Name>NotificationFlyout.Uwp.UI.Controls</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\..\src\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj">
|
||||||
|
<Project>{ade190a2-f751-4836-b8f4-bf56694a4b3f}</Project>
|
||||||
|
<Name>NotificationFlyout.Uwp.UI</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
LightIconSource="/Assets/Icon-Light.ico">
|
LightIconSource="/Assets/Icon-Light.ico">
|
||||||
<controls:NotificationFlyout.ContextMenuItems>
|
<controls:NotificationFlyout.ContextMenuItems>
|
||||||
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="Click me" />
|
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="Click me" />
|
||||||
|
<MenuFlyoutItem Click="MenuFlyoutItem_Click_1" Text="Exit" />
|
||||||
</controls:NotificationFlyout.ContextMenuItems>
|
</controls:NotificationFlyout.ContextMenuItems>
|
||||||
<StackPanel Margin="24">
|
<StackPanel Margin="24">
|
||||||
<ComboBox
|
<ComboBox
|
||||||
|
|||||||
@@ -31,5 +31,11 @@ namespace NotificationFlyoutSample
|
|||||||
MessageDialog d = new MessageDialog("Hello from context menu!");
|
MessageDialog d = new MessageDialog("Hello from context menu!");
|
||||||
d.ShowAsync();
|
d.ShowAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void MenuFlyoutItem_Click_1(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var app = GetApplication();
|
||||||
|
app.Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -28,8 +28,10 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
|||||||
typeof(ElementTheme), typeof(NotificationFlyout),
|
typeof(ElementTheme), typeof(NotificationFlyout),
|
||||||
new PropertyMetadata(ElementTheme.Default, OnRequestedThemePropertyChanged));
|
new PropertyMetadata(ElementTheme.Default, OnRequestedThemePropertyChanged));
|
||||||
|
|
||||||
|
public static INotificationFlyoutApplication _applicationInstance;
|
||||||
|
|
||||||
public static DependencyProperty ContentProperty =
|
public static DependencyProperty ContentProperty =
|
||||||
DependencyProperty.Register(nameof(Content),
|
DependencyProperty.Register(nameof(Content),
|
||||||
typeof(UIElement), typeof(NotificationFlyout),
|
typeof(UIElement), typeof(NotificationFlyout),
|
||||||
new PropertyMetadata(null, OnContentPropertyChanged));
|
new PropertyMetadata(null, OnContentPropertyChanged));
|
||||||
|
|
||||||
@@ -37,7 +39,6 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
|||||||
DependencyProperty.Register(nameof(ContextMenuItems),
|
DependencyProperty.Register(nameof(ContextMenuItems),
|
||||||
typeof(IList<MenuFlyoutItemBase>), typeof(NotificationFlyout),
|
typeof(IList<MenuFlyoutItemBase>), typeof(NotificationFlyout),
|
||||||
new PropertyMetadata(null));
|
new PropertyMetadata(null));
|
||||||
|
|
||||||
public NotificationFlyout()
|
public NotificationFlyout()
|
||||||
{
|
{
|
||||||
ContextMenuItems = new ObservableCollection<MenuFlyoutItemBase>();
|
ContextMenuItems = new ObservableCollection<MenuFlyoutItemBase>();
|
||||||
@@ -45,8 +46,11 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal event EventHandler ContentChanged;
|
internal event EventHandler ContentChanged;
|
||||||
|
|
||||||
internal event EventHandler IconSourceChanged;
|
internal event EventHandler IconSourceChanged;
|
||||||
|
|
||||||
internal event EventHandler<NotificationFlyoutMenuItemsChangedEventArgs> MenuItemsChanged;
|
internal event EventHandler<NotificationFlyoutMenuItemsChangedEventArgs> MenuItemsChanged;
|
||||||
|
|
||||||
internal event EventHandler RequestedThemeChanged;
|
internal event EventHandler RequestedThemeChanged;
|
||||||
|
|
||||||
public UIElement Content
|
public UIElement Content
|
||||||
@@ -79,6 +83,16 @@ namespace NotificationFlyout.Uwp.UI.Controls
|
|||||||
set => SetValue(RequestedThemeProperty, value);
|
set => SetValue(RequestedThemeProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static INotificationFlyoutApplication GetApplication()
|
||||||
|
{
|
||||||
|
return _applicationInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void SetApplication(INotificationFlyoutApplication application)
|
||||||
|
{
|
||||||
|
_applicationInstance = application;
|
||||||
|
}
|
||||||
|
|
||||||
private static void OnContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
private static void OnContentPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||||
{
|
{
|
||||||
var sender = dependencyObject as NotificationFlyout;
|
var sender = dependencyObject as NotificationFlyout;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace NotificationFlyout.Uwp.UI
|
||||||
|
{
|
||||||
|
public interface INotificationFlyoutApplication
|
||||||
|
{
|
||||||
|
void Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
<Project Sdk="MSBuild.Sdk.Extras">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
|
||||||
<UseWPF>true</UseWPF>
|
|
||||||
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
|
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
|
||||||
<MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.1.2" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\NotificationFlyout.Uwp.UI.Controls\NotificationFlyout.Uwp.UI.Controls.csproj" />
|
|
||||||
<ProjectReference Include="..\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj" />
|
|
||||||
<ProjectReference Include="..\NotificationFlyout.Wpf.UI\NotificationFlyout.Wpf.UI.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Update="Microsoft.VCRTForwarders.140" Version="1.0.7" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
+19
-4
@@ -1,21 +1,26 @@
|
|||||||
using System;
|
using NotificationFlyout.Uwp.UI;
|
||||||
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
|
|
||||||
namespace NotificationFlyout.Wpf.UI.Controls
|
namespace NotificationFlyout.Wpf.UI.Controls
|
||||||
{
|
{
|
||||||
[ContentProperty(nameof(Flyout))]
|
[ContentProperty(nameof(Flyout))]
|
||||||
public class NotificationFlyoutApplication : DependencyObject
|
public class NotificationFlyoutApplication : DependencyObject, INotificationFlyoutApplication
|
||||||
{
|
{
|
||||||
public static DependencyProperty FlyoutProperty =
|
public static DependencyProperty FlyoutProperty =
|
||||||
DependencyProperty.Register(nameof(Flyout),
|
DependencyProperty.Register(nameof(Flyout),
|
||||||
typeof(Uwp.UI.Controls.NotificationFlyout), typeof(NotificationFlyoutApplication),
|
typeof(Uwp.UI.Controls.NotificationFlyout), typeof(NotificationFlyoutApplication),
|
||||||
new PropertyMetadata(null, OnFlyoutPropertyChanged));
|
new PropertyMetadata(null, OnFlyoutPropertyChanged));
|
||||||
|
|
||||||
|
private static NotificationFlyoutApplication _instance;
|
||||||
private readonly ContextMenuXamlHost _contextMenuXamlHost;
|
private readonly ContextMenuXamlHost _contextMenuXamlHost;
|
||||||
private readonly NotificationFlyoutXamlHost _notificationFlyoutXamlHost;
|
private readonly NotificationFlyoutXamlHost _notificationFlyoutXamlHost;
|
||||||
|
|
||||||
public NotificationFlyoutApplication()
|
public NotificationFlyoutApplication()
|
||||||
{
|
{
|
||||||
|
_instance = this;
|
||||||
|
|
||||||
_notificationFlyoutXamlHost = new NotificationFlyoutXamlHost();
|
_notificationFlyoutXamlHost = new NotificationFlyoutXamlHost();
|
||||||
_notificationFlyoutXamlHost.ContextMenuRequested += OnContextMenuRequested;
|
_notificationFlyoutXamlHost.ContextMenuRequested += OnContextMenuRequested;
|
||||||
_notificationFlyoutXamlHost.Show();
|
_notificationFlyoutXamlHost.Show();
|
||||||
@@ -24,12 +29,20 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
_contextMenuXamlHost.Show();
|
_contextMenuXamlHost.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static INotificationFlyoutApplication Current => _instance;
|
||||||
|
|
||||||
public Uwp.UI.Controls.NotificationFlyout Flyout
|
public Uwp.UI.Controls.NotificationFlyout Flyout
|
||||||
{
|
{
|
||||||
get => (Uwp.UI.Controls.NotificationFlyout)GetValue(FlyoutProperty);
|
get => (Uwp.UI.Controls.NotificationFlyout)GetValue(FlyoutProperty);
|
||||||
set => SetValue(FlyoutProperty, value);
|
set => SetValue(FlyoutProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Exit()
|
||||||
|
{
|
||||||
|
_contextMenuXamlHost.Close();
|
||||||
|
_notificationFlyoutXamlHost.Close();
|
||||||
|
}
|
||||||
|
|
||||||
public void HideFlyout()
|
public void HideFlyout()
|
||||||
{
|
{
|
||||||
_notificationFlyoutXamlHost.HideFlyout();
|
_notificationFlyoutXamlHost.HideFlyout();
|
||||||
@@ -53,8 +66,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
|
|
||||||
private void OnFlyoutPropertyChanged()
|
private void OnFlyoutPropertyChanged()
|
||||||
{
|
{
|
||||||
_notificationFlyoutXamlHost.SetFlyout(Flyout);
|
_notificationFlyoutXamlHost?.SetFlyout(Flyout);
|
||||||
_contextMenuXamlHost.SetFlyout(Flyout);
|
_contextMenuXamlHost?.SetFlyout(Flyout);
|
||||||
|
|
||||||
|
Uwp.UI.Controls.NotificationFlyout.SetApplication(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
@@ -136,6 +136,11 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
_taskbarHelper.TaskbarChanged += OnTaskbarChanged;
|
_taskbarHelper.TaskbarChanged += OnTaskbarChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnClosed(EventArgs args)
|
||||||
|
{
|
||||||
|
_notificationIconHelper.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateFlyoutContent()
|
private void UpdateFlyoutContent()
|
||||||
{
|
{
|
||||||
if (_flyout == null) return;
|
if (_flyout == null) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user