Move *everything* from setting flyout content and the flyout icons to a UWP control and simplified creation of the wpf host via a NotificationFlyoutApplication where you only need to set the UWP flyout
This commit is contained in:
@@ -11,11 +11,6 @@
|
|||||||
<EnableXBindDiagnostics>false</EnableXBindDiagnostics>
|
<EnableXBindDiagnostics>false</EnableXBindDiagnostics>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="Assets\Icon-Light.ico" />
|
|
||||||
<None Remove="Assets\Icon.ico" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.1.2" />
|
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.1.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -26,10 +21,5 @@
|
|||||||
<ProjectReference Include="..\..\src\NotificationFlyout.Wpf.UI\NotificationFlyout.Wpf.UI.csproj" />
|
<ProjectReference Include="..\..\src\NotificationFlyout.Wpf.UI\NotificationFlyout.Wpf.UI.csproj" />
|
||||||
<ProjectReference Include="..\NotificationFlyoutSample\NotificationFlyoutSample.csproj" />
|
<ProjectReference Include="..\NotificationFlyoutSample\NotificationFlyoutSample.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Resource Include="Assets\Icon-Light.ico" />
|
|
||||||
<Resource Include="Assets\Icon.ico" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using NotificationFlyout.Wpf.UI.Controls;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace NotificationFlyoutSample.Host
|
namespace NotificationFlyoutSample.Host
|
||||||
{
|
{
|
||||||
@@ -10,7 +11,10 @@ namespace NotificationFlyoutSample.Host
|
|||||||
using (new NotificationFlyoutSample.App())
|
using (new NotificationFlyoutSample.App())
|
||||||
{
|
{
|
||||||
var app = new App();
|
var app = new App();
|
||||||
new SampleNotificationFlyout();
|
new NotificationFlyoutApplication
|
||||||
|
{
|
||||||
|
Flyout = new Shell()
|
||||||
|
};
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<NotificationFlyout
|
|
||||||
x:Class="NotificationFlyoutSample.Host.SampleNotificationFlyout"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:uwp="clr-namespace:NotificationFlyoutSample;assembly=NotificationFlyoutSample"
|
|
||||||
IconSource="/Assets/Icon.ico"
|
|
||||||
LightIconSource="/Assets/Icon-Light.ico">
|
|
||||||
<uwp:Shell />
|
|
||||||
</NotificationFlyout>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace NotificationFlyoutSample.Host
|
|
||||||
{
|
|
||||||
public partial class SampleNotificationFlyout
|
|
||||||
{
|
|
||||||
public SampleNotificationFlyout()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
@@ -130,6 +130,8 @@
|
|||||||
</AppxManifest>
|
</AppxManifest>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="Assets\Icon-Light.ico" />
|
||||||
|
<Content Include="Assets\Icon.ico" />
|
||||||
<Content Include="Properties\Default.rd.xml" />
|
<Content Include="Properties\Default.rd.xml" />
|
||||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
<UserControl
|
<controls:NotificationFlyout
|
||||||
x:Class="NotificationFlyoutSample.Shell"
|
x:Class="NotificationFlyoutSample.Shell"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:winui="using:Microsoft.UI.Xaml.Controls">
|
xmlns:controls="using:NotificationFlyout.Uwp.UI.Controls"
|
||||||
<StackPanel
|
xmlns:winui="using:Microsoft.UI.Xaml.Controls"
|
||||||
Width="330"
|
LightIconSource="/Assets/Icon.ico">
|
||||||
Height="500"
|
<controls:NotificationFlyout.Content>
|
||||||
Margin="24">
|
<StackPanel
|
||||||
<ComboBox x:Name="Theme" SelectionChanged="Theme_SelectionChanged">
|
Width="330"
|
||||||
<ComboBoxItem Content="Default" />
|
Height="500"
|
||||||
<ComboBoxItem Content="Dark" />
|
Margin="24">
|
||||||
<ComboBoxItem Content="Light" />
|
<ComboBox x:Name="Theme" SelectionChanged="Theme_SelectionChanged">
|
||||||
</ComboBox>
|
<ComboBoxItem Content="Default" />
|
||||||
<Button Margin="0,0,0,8" Content="Button" />
|
<ComboBoxItem Content="Dark" />
|
||||||
<Slider Margin="0,0,0,8" />
|
<ComboBoxItem Content="Light" />
|
||||||
<TextBox Margin="0,0,0,8" />
|
</ComboBox>
|
||||||
<ToggleButton Margin="0,0,0,8" />
|
<Button Margin="0,0,0,8" Content="Button" />
|
||||||
<CalendarView Margin="0,0,0,8" />
|
<Slider Margin="0,0,0,8" />
|
||||||
</StackPanel>
|
<TextBox Margin="0,0,0,8" />
|
||||||
</UserControl>
|
<ToggleButton Margin="0,0,0,8" />
|
||||||
|
<CalendarView Margin="0,0,0,8" />
|
||||||
|
</StackPanel>
|
||||||
|
</controls:NotificationFlyout.Content>
|
||||||
|
</controls:NotificationFlyout>
|
||||||
|
|||||||
@@ -9,18 +9,18 @@
|
|||||||
|
|
||||||
private void Theme_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
|
private void Theme_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
switch (Theme.SelectedIndex)
|
//switch (Theme.SelectedIndex)
|
||||||
{
|
//{
|
||||||
case 0:
|
// case 0:
|
||||||
RequestedTheme = Windows.UI.Xaml.ElementTheme.Default;
|
// RequestedTheme = Windows.UI.Xaml.ElementTheme.Default;
|
||||||
break;
|
// break;
|
||||||
case 1:
|
// case 1:
|
||||||
RequestedTheme = Windows.UI.Xaml.ElementTheme.Dark;
|
// RequestedTheme = Windows.UI.Xaml.ElementTheme.Dark;
|
||||||
break;
|
// break;
|
||||||
case 2:
|
// case 2:
|
||||||
RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;
|
// RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;
|
||||||
break;
|
// break;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Shared.UI
|
||||||
|
{
|
||||||
|
public static class ImageSourceExtensions
|
||||||
|
{
|
||||||
|
public static Icon ConvertToIcon(this ImageSource imageSource, uint dpi)
|
||||||
|
{
|
||||||
|
if (imageSource == null) return null;
|
||||||
|
|
||||||
|
var uri = new Uri(imageSource.ToString(), UriKind.RelativeOrAbsolute);
|
||||||
|
|
||||||
|
var streamResource = Application.GetResourceStream(uri);
|
||||||
|
if (streamResource == null) throw new ArgumentException(nameof(streamResource));
|
||||||
|
|
||||||
|
return new Icon(streamResource.Stream, new System.Drawing.Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum SystemMetricFlag : int
|
||||||
|
{
|
||||||
|
SM_CXICON = 11,
|
||||||
|
SM_CYICON = 12,
|
||||||
|
SM_CXSMICON = 49,
|
||||||
|
SM_CYSMICON = 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -8,11 +8,11 @@
|
|||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Page Include="NotificationFlyoutHost\NotificationFlyoutHost.xaml">
|
<Page Include="NotificationFlyout\NotificationFlyoutHost.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
<Page Include="NotificationFlyoutPresenter\NotificationFlyoutPresenter.xaml">
|
<Page Include="NotificationFlyout\NotificationFlyoutPresenter.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Uwp.UI.Controls
|
||||||
|
{
|
||||||
|
public class NotificationFlyout : DependencyObject
|
||||||
|
{
|
||||||
|
public static readonly DependencyProperty IconSourceProperty =
|
||||||
|
DependencyProperty.Register(nameof(IconSource),
|
||||||
|
typeof(ImageSource), typeof(NotificationFlyout),
|
||||||
|
new PropertyMetadata(null, OnIconPropertyChanged));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty LightIconSourceProperty =
|
||||||
|
DependencyProperty.Register(nameof(LightIconSource),
|
||||||
|
typeof(ImageSource), typeof(NotificationFlyout),
|
||||||
|
new PropertyMetadata(null, OnIconPropertyChanged));
|
||||||
|
|
||||||
|
public static DependencyProperty ContentProperty =
|
||||||
|
DependencyProperty.Register(nameof(Content),
|
||||||
|
typeof(UIElement), typeof(NotificationFlyout),
|
||||||
|
new PropertyMetadata(null));
|
||||||
|
|
||||||
|
internal event EventHandler ContentChanged;
|
||||||
|
internal event EventHandler IconSourceChanged;
|
||||||
|
|
||||||
|
public UIElement Content
|
||||||
|
{
|
||||||
|
get => (UIElement)GetValue(ContentProperty);
|
||||||
|
set => SetValue(ContentProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageSource IconSource
|
||||||
|
{
|
||||||
|
get => (ImageSource)GetValue(IconSourceProperty);
|
||||||
|
set => SetValue(IconSourceProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageSource LightIconSource
|
||||||
|
{
|
||||||
|
get => (ImageSource)GetValue(LightIconSourceProperty);
|
||||||
|
set => SetValue(LightIconSourceProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnIconPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
||||||
|
{
|
||||||
|
var sender = dependencyObject as NotificationFlyout;
|
||||||
|
sender?.OnIconPropertyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnIconPropertyChanged()
|
||||||
|
{
|
||||||
|
IconSourceChanged?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
[assembly: AssemblyTitle("NotificationFlyout.Uwp.UI.Controls")]
|
[assembly: AssemblyTitle("NotificationFlyout.Uwp.UI.Controls")]
|
||||||
@@ -11,4 +12,5 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
[assembly: InternalsVisibleTo("NotificationFlyout.Wpf.UI.Controls")]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutHost/NotificationFlyoutHost.xaml" />
|
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutHost.xaml" />
|
||||||
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyoutPresenter/NotificationFlyoutPresenter.xaml" />
|
<ResourceDictionary Source="ms-appx:///NotificationFlyout.Uwp.UI.Controls/NotificationFlyout/NotificationFlyoutPresenter.xaml" />
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using Microsoft.Windows.Sdk;
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Uwp.UI.Extensions
|
||||||
|
{
|
||||||
|
public static class ImageSourceExtensions
|
||||||
|
{
|
||||||
|
public static Icon ConvertToIcon(this ImageSource imageSource, uint dpi)
|
||||||
|
{
|
||||||
|
var bitmapImage = (BitmapImage)imageSource;
|
||||||
|
var uri = $"{AppDomain.CurrentDomain.BaseDirectory}{bitmapImage.UriSource}".Replace("ms-appx:///", "").Replace("/", "\\");
|
||||||
|
|
||||||
|
using var stream = File.OpenRead(uri);
|
||||||
|
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum SystemMetricFlag : int
|
||||||
|
{
|
||||||
|
SM_CXICON = 11,
|
||||||
|
SM_CYICON = 12,
|
||||||
|
SM_CXSMICON = 49,
|
||||||
|
SM_CYSMICON = 50
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
GetSystemMetricsForDpi
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="MSBuild.Sdk.Extras">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>uap10.0.19041</TargetFrameworks>
|
||||||
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
|
<EnableTypeInfoReflection>false</EnableTypeInfoReflection>
|
||||||
|
<EnableXBindDiagnostics>false</EnableXBindDiagnostics>
|
||||||
|
<LangVersion>9.0</LangVersion>
|
||||||
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="NotificationFlyout\**" />
|
||||||
|
<EmbeddedResource Remove="NotificationFlyout\**" />
|
||||||
|
<None Remove="NotificationFlyout\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="NativeMethods.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<AdditionalFiles Include="NativeMethods.txt" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.1.319-beta">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\NotificationFlyout.Uwp.UI.Controls\NotificationFlyout.Uwp.UI.Controls.csproj" />
|
<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" />
|
<ProjectReference Include="..\NotificationFlyout.Wpf.UI\NotificationFlyout.Wpf.UI.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
using System.Windows;
|
|
||||||
using System.Windows.Markup;
|
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace NotificationFlyout.Wpf.UI.Controls
|
|
||||||
{
|
|
||||||
[ContentProperty(nameof(Content))]
|
|
||||||
public class NotificationFlyout : DependencyObject
|
|
||||||
{
|
|
||||||
public static readonly DependencyProperty IconSourceProperty =
|
|
||||||
DependencyProperty.Register(nameof(IconSource),
|
|
||||||
typeof(ImageSource), typeof(NotificationFlyout),
|
|
||||||
new PropertyMetadata(null, OnIconPropertyChanged));
|
|
||||||
|
|
||||||
public static readonly DependencyProperty LightIconSourceProperty =
|
|
||||||
DependencyProperty.Register(nameof(LightIconSource),
|
|
||||||
typeof(ImageSource), typeof(NotificationFlyout),
|
|
||||||
new PropertyMetadata(null, OnIconPropertyChanged));
|
|
||||||
|
|
||||||
public static DependencyProperty ContentProperty =
|
|
||||||
DependencyProperty.Register(nameof(Content),
|
|
||||||
typeof(Windows.UI.Xaml.UIElement), typeof(NotificationFlyout),
|
|
||||||
new PropertyMetadata(null, OnFlyoutPresenterPropertyChanged));
|
|
||||||
|
|
||||||
private readonly NotificationFlyoutXamlHost _xamlHost;
|
|
||||||
|
|
||||||
public NotificationFlyout()
|
|
||||||
{
|
|
||||||
_xamlHost = new NotificationFlyoutXamlHost();
|
|
||||||
_xamlHost.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Windows.UI.Xaml.UIElement Content
|
|
||||||
{
|
|
||||||
get => (Windows.UI.Xaml.UIElement)GetValue(ContentProperty);
|
|
||||||
set => SetValue(ContentProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageSource IconSource
|
|
||||||
{
|
|
||||||
get => (ImageSource)GetValue(IconSourceProperty);
|
|
||||||
set => SetValue(IconSourceProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageSource LightIconSource
|
|
||||||
{
|
|
||||||
get => (ImageSource)GetValue(LightIconSourceProperty);
|
|
||||||
set => SetValue(LightIconSourceProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HideFlyout()
|
|
||||||
{
|
|
||||||
_xamlHost.HideFlyout();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ShowFlyout()
|
|
||||||
{
|
|
||||||
_xamlHost.ShowFlyout();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnFlyoutPresenterPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
|
||||||
{
|
|
||||||
var sender = dependencyObject as NotificationFlyout;
|
|
||||||
sender?.OnFlyoutPresenterPropertyChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void OnIconPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
|
|
||||||
{
|
|
||||||
var sender = dependencyObject as NotificationFlyout;
|
|
||||||
sender?.OnIconPropertyChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnFlyoutPresenterPropertyChanged()
|
|
||||||
{
|
|
||||||
_xamlHost.SetFlyoutContent(Content);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnIconPropertyChanged()
|
|
||||||
{
|
|
||||||
_xamlHost.SetIcons(IconSource, LightIconSource);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Markup;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Wpf.UI.Controls
|
||||||
|
{
|
||||||
|
[ContentProperty(nameof(Flyout))]
|
||||||
|
public class NotificationFlyoutApplication : DependencyObject
|
||||||
|
{
|
||||||
|
public static DependencyProperty FlyoutProperty =
|
||||||
|
DependencyProperty.Register(nameof(Flyout),
|
||||||
|
typeof(Uwp.UI.Controls.NotificationFlyout), typeof(NotificationFlyoutApplication),
|
||||||
|
new PropertyMetadata(null, OnFlyoutPropertyChanged));
|
||||||
|
|
||||||
|
private readonly NotificationFlyoutXamlHost _xamlHost;
|
||||||
|
|
||||||
|
public NotificationFlyoutApplication()
|
||||||
|
{
|
||||||
|
_xamlHost = new NotificationFlyoutXamlHost();
|
||||||
|
_xamlHost.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uwp.UI.Controls.NotificationFlyout Flyout
|
||||||
|
{
|
||||||
|
get => (Uwp.UI.Controls.NotificationFlyout)GetValue(FlyoutProperty);
|
||||||
|
set => SetValue(FlyoutProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideFlyout()
|
||||||
|
{
|
||||||
|
_xamlHost.HideFlyout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowFlyout()
|
||||||
|
{
|
||||||
|
_xamlHost.ShowFlyout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnFlyoutPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
|
||||||
|
{
|
||||||
|
var sender = dependencyObject as NotificationFlyoutApplication;
|
||||||
|
sender?.OnFlyoutPropertyChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFlyoutPropertyChanged()
|
||||||
|
{
|
||||||
|
_xamlHost.SetFlyout(Flyout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
-17
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
||||||
using NotificationFlyout.Uwp.UI.Controls;
|
using NotificationFlyout.Uwp.UI.Controls;
|
||||||
using NotificationFlyout.Wpf.UI.Extensions;
|
using NotificationFlyout.Wpf.UI.Extensions;
|
||||||
|
using NotificationFlyout.Uwp.UI.Extensions;
|
||||||
using NotificationFlyout.Wpf.UI.Helpers;
|
using NotificationFlyout.Wpf.UI.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -14,9 +15,8 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
||||||
private const double WindowSize = 5;
|
private const double WindowSize = 5;
|
||||||
|
|
||||||
private ImageSource _defaultIconSource;
|
private Uwp.UI.Controls.NotificationFlyout _flyout;
|
||||||
private bool _isLoaded;
|
private bool _isLoaded;
|
||||||
private ImageSource _lightIconSource;
|
|
||||||
private NotificationIconHelper _notificationIconHelper;
|
private NotificationIconHelper _notificationIconHelper;
|
||||||
private SystemPersonalisationHelper _systemPersonalisationHelper;
|
private SystemPersonalisationHelper _systemPersonalisationHelper;
|
||||||
private TaskbarHelper _taskbarHelper;
|
private TaskbarHelper _taskbarHelper;
|
||||||
@@ -30,13 +30,25 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
Loaded += OnLoaded;
|
Loaded += OnLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetFlyoutContent(Windows.UI.Xaml.UIElement content)
|
public void SetFlyout(Uwp.UI.Controls.NotificationFlyout flyout)
|
||||||
{
|
{
|
||||||
var flyoutHost = GetFlyoutHost();
|
if (_flyout != null)
|
||||||
if (flyoutHost != null)
|
|
||||||
{
|
{
|
||||||
flyoutHost.Content = content;
|
_flyout.ContentChanged -= OnFlyoutContentChanged;
|
||||||
|
_flyout.IconSourceChanged -= OnFlyoutIconSourceChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_flyout = flyout;
|
||||||
|
_flyout.ContentChanged += OnFlyoutContentChanged;
|
||||||
|
_flyout.IconSourceChanged += OnFlyoutIconSourceChanged;
|
||||||
|
|
||||||
|
UpdateFlyoutContent();
|
||||||
|
UpdateIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnFlyoutIconSourceChanged(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
UpdateIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void HideFlyout()
|
internal void HideFlyout()
|
||||||
@@ -48,14 +60,6 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetIcons(ImageSource defaultIconSource, ImageSource lightIconSource)
|
|
||||||
{
|
|
||||||
_defaultIconSource = defaultIconSource;
|
|
||||||
_lightIconSource = lightIconSource;
|
|
||||||
|
|
||||||
UpdateIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ShowFlyout()
|
internal void ShowFlyout()
|
||||||
{
|
{
|
||||||
var flyoutHost = GetFlyoutHost();
|
var flyoutHost = GetFlyoutHost();
|
||||||
@@ -82,6 +86,11 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
return _xamlHost.GetUwpInternalObject() as NotificationFlyoutHost;
|
return _xamlHost.GetUwpInternalObject() as NotificationFlyoutHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnFlyoutContentChanged(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
UpdateFlyoutContent();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
private void OnIconInvoked(object sender, NotificationIconInvokedEventArgs args)
|
||||||
{
|
{
|
||||||
ShowFlyout();
|
ShowFlyout();
|
||||||
@@ -95,7 +104,6 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
_isLoaded = true;
|
_isLoaded = true;
|
||||||
|
|
||||||
UpdateWindow();
|
UpdateWindow();
|
||||||
UpdateIcon();
|
|
||||||
this.Hidden();
|
this.Hidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +114,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
|
|
||||||
private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args)
|
private void OnThemeChanged(object sender, SystemPersonalisationChangedEventArgs args)
|
||||||
{
|
{
|
||||||
UpdateIcon();
|
UpdateIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareDefaultWindow()
|
private void PrepareDefaultWindow()
|
||||||
@@ -149,10 +157,29 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
Content = _xamlHost;
|
Content = _xamlHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateIcon()
|
private void UpdateFlyoutContent()
|
||||||
|
{
|
||||||
|
if (_flyout == null) return;
|
||||||
|
|
||||||
|
var content = _flyout.Content;
|
||||||
|
if (content == null) return;
|
||||||
|
|
||||||
|
var flyoutHost = GetFlyoutHost();
|
||||||
|
if (flyoutHost != null)
|
||||||
|
{
|
||||||
|
flyoutHost.Content = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateIcons()
|
||||||
{
|
{
|
||||||
if (!_isLoaded) return;
|
if (!_isLoaded) return;
|
||||||
|
|
||||||
|
if (_flyout == null) return;
|
||||||
|
|
||||||
|
var _defaultIconSource = _flyout.IconSource;
|
||||||
|
var _lightIconSource = _flyout.LightIconSource;
|
||||||
|
|
||||||
var shellTrayHandle = WindowHelper.GetHandle(ShellTrayHandleName);
|
var shellTrayHandle = WindowHelper.GetHandle(ShellTrayHandleName);
|
||||||
if (shellTrayHandle == null) return;
|
if (shellTrayHandle == null) return;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
global.json = global.json
|
global.json = global.json
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotificationFlyout.Uwp.UI", "NotificationFlyout.Uwp.UI\NotificationFlyout.Uwp.UI.csproj", "{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -88,6 +90,26 @@ Global
|
|||||||
{29430194-7EDE-4C33-AF59-CE121F48F66E}.Release|x64.Build.0 = Release|x64
|
{29430194-7EDE-4C33-AF59-CE121F48F66E}.Release|x64.Build.0 = Release|x64
|
||||||
{29430194-7EDE-4C33-AF59-CE121F48F66E}.Release|x86.ActiveCfg = Release|Any CPU
|
{29430194-7EDE-4C33-AF59-CE121F48F66E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{29430194-7EDE-4C33-AF59-CE121F48F66E}.Release|x86.Build.0 = Release|Any CPU
|
{29430194-7EDE-4C33-AF59-CE121F48F66E}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|ARM.Build.0 = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|ARM64.Build.0 = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{3FE0D7F7-1173-4989-BE6C-AD28FE0D4AC9}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user