Added API for closing FlyoutApplication from the Flyout control in two seperate projects.

This commit is contained in:
Daniel Clark
2021-02-11 10:44:07 +00:00
parent 50d817a658
commit fd46a44988
10 changed files with 85 additions and 31 deletions
@@ -18,6 +18,8 @@ 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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotificationFlyout.Uwp.UI", "..\..\src\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj", "{ADE190A2-F751-4836-B8F4-BF56694A4B3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
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|x86.ActiveCfg = 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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -169,6 +169,10 @@
<Project>{95f851e4-87a5-4bb7-953e-c0fe3b306f0e}</Project>
<Name>NotificationFlyout.Uwp.UI.Controls</Name>
</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>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
@@ -8,6 +8,7 @@
LightIconSource="/Assets/Icon-Light.ico">
<controls:NotificationFlyout.ContextMenuItems>
<MenuFlyoutItem Click="MenuFlyoutItem_Click" Text="Click me" />
<MenuFlyoutItem Click="MenuFlyoutItem_Click_1" Text="Exit" />
</controls:NotificationFlyout.ContextMenuItems>
<StackPanel Margin="24">
<ComboBox
@@ -31,5 +31,11 @@ namespace NotificationFlyoutSample
MessageDialog d = new MessageDialog("Hello from context menu!");
d.ShowAsync();
}
private void MenuFlyoutItem_Click_1(object sender, RoutedEventArgs e)
{
var app = GetApplication();
app.Exit();
}
}
}
@@ -28,4 +28,9 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj" />
</ItemGroup>
</Project>
@@ -28,6 +28,8 @@ namespace NotificationFlyout.Uwp.UI.Controls
typeof(ElementTheme), typeof(NotificationFlyout),
new PropertyMetadata(ElementTheme.Default, OnRequestedThemePropertyChanged));
public static INotificationFlyoutApplication _applicationInstance;
public static DependencyProperty ContentProperty =
DependencyProperty.Register(nameof(Content),
typeof(UIElement), typeof(NotificationFlyout),
@@ -37,7 +39,6 @@ namespace NotificationFlyout.Uwp.UI.Controls
DependencyProperty.Register(nameof(ContextMenuItems),
typeof(IList<MenuFlyoutItemBase>), typeof(NotificationFlyout),
new PropertyMetadata(null));
public NotificationFlyout()
{
ContextMenuItems = new ObservableCollection<MenuFlyoutItemBase>();
@@ -45,8 +46,11 @@ namespace NotificationFlyout.Uwp.UI.Controls
}
internal event EventHandler ContentChanged;
internal event EventHandler IconSourceChanged;
internal event EventHandler<NotificationFlyoutMenuItemsChangedEventArgs> MenuItemsChanged;
internal event EventHandler RequestedThemeChanged;
public UIElement Content
@@ -79,6 +83,16 @@ namespace NotificationFlyout.Uwp.UI.Controls
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)
{
var sender = dependencyObject as NotificationFlyout;
@@ -0,0 +1,7 @@
namespace NotificationFlyout.Uwp.UI
{
public interface INotificationFlyoutApplication
{
void Exit();
}
}
@@ -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>
@@ -1,21 +1,26 @@
using System;
using NotificationFlyout.Uwp.UI;
using System;
using System.Windows;
using System.Windows.Markup;
namespace NotificationFlyout.Wpf.UI.Controls
{
[ContentProperty(nameof(Flyout))]
public class NotificationFlyoutApplication : DependencyObject
public class NotificationFlyoutApplication : DependencyObject, INotificationFlyoutApplication
{
public static DependencyProperty FlyoutProperty =
DependencyProperty.Register(nameof(Flyout),
typeof(Uwp.UI.Controls.NotificationFlyout), typeof(NotificationFlyoutApplication),
new PropertyMetadata(null, OnFlyoutPropertyChanged));
private static NotificationFlyoutApplication _instance;
private readonly ContextMenuXamlHost _contextMenuXamlHost;
private readonly NotificationFlyoutXamlHost _notificationFlyoutXamlHost;
public NotificationFlyoutApplication()
{
_instance = this;
_notificationFlyoutXamlHost = new NotificationFlyoutXamlHost();
_notificationFlyoutXamlHost.ContextMenuRequested += OnContextMenuRequested;
_notificationFlyoutXamlHost.Show();
@@ -24,12 +29,20 @@ namespace NotificationFlyout.Wpf.UI.Controls
_contextMenuXamlHost.Show();
}
public static INotificationFlyoutApplication Current => _instance;
public Uwp.UI.Controls.NotificationFlyout Flyout
{
get => (Uwp.UI.Controls.NotificationFlyout)GetValue(FlyoutProperty);
set => SetValue(FlyoutProperty, value);
}
public void Exit()
{
_contextMenuXamlHost.Close();
_notificationFlyoutXamlHost.Close();
}
public void HideFlyout()
{
_notificationFlyoutXamlHost.HideFlyout();
@@ -53,8 +66,10 @@ namespace NotificationFlyout.Wpf.UI.Controls
private void OnFlyoutPropertyChanged()
{
_notificationFlyoutXamlHost.SetFlyout(Flyout);
_contextMenuXamlHost.SetFlyout(Flyout);
_notificationFlyoutXamlHost?.SetFlyout(Flyout);
_contextMenuXamlHost?.SetFlyout(Flyout);
Uwp.UI.Controls.NotificationFlyout.SetApplication(this);
}
}
}
@@ -136,6 +136,11 @@ namespace NotificationFlyout.Wpf.UI.Controls
_taskbarHelper.TaskbarChanged += OnTaskbarChanged;
}
protected override void OnClosed(EventArgs args)
{
_notificationIconHelper.Dispose();
}
private void UpdateFlyoutContent()
{
if (_flyout == null) return;