Added API for closing FlyoutApplication from the Flyout control in two seperate projects.
This commit is contained in:
@@ -27,5 +27,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -28,8 +28,10 @@ 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),
|
||||
DependencyProperty.Register(nameof(Content),
|
||||
typeof(UIElement), typeof(NotificationFlyout),
|
||||
new PropertyMetadata(null, OnContentPropertyChanged));
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
-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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user