Added API for opening a window from flyout w/ sample
This commit is contained in:
@@ -123,6 +123,9 @@
|
|||||||
<Compile Include="Shell.xaml.cs">
|
<Compile Include="Shell.xaml.cs">
|
||||||
<DependentUpon>Shell.xaml</DependentUpon>
|
<DependentUpon>Shell.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="WindowContent.xaml.cs">
|
||||||
|
<DependentUpon>WindowContent.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AppxManifest Include="Package.appxmanifest">
|
<AppxManifest Include="Package.appxmanifest">
|
||||||
@@ -163,6 +166,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="WindowContent.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\NotificationFlyout.Uwp.UI.Controls\NotificationFlyout.Uwp.UI.Controls.csproj">
|
<ProjectReference Include="..\..\src\NotificationFlyout.Uwp.UI.Controls\NotificationFlyout.Uwp.UI.Controls.csproj">
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
IsIndeterminate="True"
|
IsIndeterminate="True"
|
||||||
ShowError="False"
|
ShowError="False"
|
||||||
ShowPaused="False" />
|
ShowPaused="False" />
|
||||||
<Button Margin="0,0,0,8" Content="Button" />
|
<Button Margin="0,0,0,8" Content="Open window" Click="Button_Click" />
|
||||||
<Slider Margin="0,0,0,8" />
|
<Slider Margin="0,0,0,8" />
|
||||||
<TextBox Margin="0,0,0,8" />
|
<TextBox Margin="0,0,0,8" />
|
||||||
<CalendarView Margin="0,0,0,8" />
|
<CalendarView Margin="0,0,0,8" />
|
||||||
|
|||||||
@@ -28,5 +28,11 @@
|
|||||||
var app = GetApplication();
|
var app = GetApplication();
|
||||||
app.Exit();
|
app.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var app = GetApplication();
|
||||||
|
app.OpenAsWindow<WindowContent>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<UserControl
|
||||||
|
x:Class="NotificationFlyoutSample.WindowContent"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:muxc="using:Microsoft.UI.Xaml.Controls">
|
||||||
|
<muxc:NavigationView x:Name="nvSample">
|
||||||
|
<muxc:NavigationView.MenuItems>
|
||||||
|
<muxc:NavigationViewItem
|
||||||
|
Content="Menu Item1"
|
||||||
|
Icon="Play"
|
||||||
|
Tag="SamplePage1" />
|
||||||
|
<muxc:NavigationViewItem
|
||||||
|
Content="Menu Item2"
|
||||||
|
Icon="Save"
|
||||||
|
Tag="SamplePage2" />
|
||||||
|
<muxc:NavigationViewItem
|
||||||
|
Content="Menu Item3"
|
||||||
|
Icon="Refresh"
|
||||||
|
Tag="SamplePage3" />
|
||||||
|
<muxc:NavigationViewItem
|
||||||
|
Content="Menu Item4"
|
||||||
|
Icon="Download"
|
||||||
|
Tag="SamplePage4" />
|
||||||
|
</muxc:NavigationView.MenuItems>
|
||||||
|
<Frame x:Name="contentFrame" />
|
||||||
|
</muxc:NavigationView>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||||
|
|
||||||
|
namespace NotificationFlyoutSample
|
||||||
|
{
|
||||||
|
public sealed partial class WindowContent : UserControl
|
||||||
|
{
|
||||||
|
public WindowContent()
|
||||||
|
{
|
||||||
|
this.InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
namespace NotificationFlyout.Uwp.UI
|
using Windows.UI.Xaml;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Uwp.UI
|
||||||
{
|
{
|
||||||
public interface INotificationFlyoutApplication
|
public interface INotificationFlyoutApplication
|
||||||
{
|
{
|
||||||
void Exit();
|
void Exit();
|
||||||
|
|
||||||
|
void OpenAsWindow<TUIElement>() where TUIElement : UIElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -48,6 +48,12 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
_notificationFlyoutXamlHost.HideFlyout();
|
_notificationFlyoutXamlHost.HideFlyout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OpenAsWindow<TUIElement>() where TUIElement : Windows.UI.Xaml.UIElement
|
||||||
|
{
|
||||||
|
var window = new XamlHost<TUIElement>();
|
||||||
|
window.Show();
|
||||||
|
}
|
||||||
|
|
||||||
public void ShowFlyout()
|
public void ShowFlyout()
|
||||||
{
|
{
|
||||||
_notificationFlyoutXamlHost.ShowFlyout();
|
_notificationFlyoutXamlHost.ShowFlyout();
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
|
||||||
using NotificationFlyout.Wpf.UI.Extensions;
|
|
||||||
using System;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace NotificationFlyout.Wpf.UI.Controls
|
|
||||||
{
|
|
||||||
internal class XamlHostWindow<TXamlContent> : Window where TXamlContent : Windows.UI.Xaml.UIElement
|
|
||||||
{
|
|
||||||
internal const double WindowSize = 5;
|
|
||||||
protected new bool IsLoaded;
|
|
||||||
private WindowsXamlHost _xamlHost;
|
|
||||||
public XamlHostWindow()
|
|
||||||
{
|
|
||||||
PrepareDefaultWindow();
|
|
||||||
PrepareWindowsXamlHost();
|
|
||||||
|
|
||||||
Loaded += OnLoaded;
|
|
||||||
ContentRendered += OnContentRendered;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal TXamlContent GetHostContent()
|
|
||||||
{
|
|
||||||
if (_xamlHost == null) return null;
|
|
||||||
return _xamlHost.GetUwpInternalObject() as TXamlContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnContentLoaded()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnContentRendered(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
IsLoaded = true;
|
|
||||||
OnContentLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnLoaded(object sender, RoutedEventArgs args)
|
|
||||||
{
|
|
||||||
this.Hidden();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PrepareDefaultWindow()
|
|
||||||
{
|
|
||||||
ShowInTaskbar = false;
|
|
||||||
ShowActivated = false;
|
|
||||||
WindowStyle = WindowStyle.None;
|
|
||||||
ResizeMode = ResizeMode.NoResize;
|
|
||||||
AllowsTransparency = true;
|
|
||||||
Background = new SolidColorBrush(Colors.Transparent);
|
|
||||||
Height = WindowSize;
|
|
||||||
Width = WindowSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PrepareWindowsXamlHost()
|
|
||||||
{
|
|
||||||
_xamlHost = new WindowsXamlHost
|
|
||||||
{
|
|
||||||
InitialTypeName = typeof(TXamlContent).FullName,
|
|
||||||
Height = 0,
|
|
||||||
Width = 0,
|
|
||||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
|
||||||
VerticalAlignment = VerticalAlignment.Stretch
|
|
||||||
};
|
|
||||||
|
|
||||||
Content = _xamlHost;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -7,7 +7,7 @@ using Windows.UI.Xaml.Controls;
|
|||||||
|
|
||||||
namespace NotificationFlyout.Wpf.UI.Controls
|
namespace NotificationFlyout.Wpf.UI.Controls
|
||||||
{
|
{
|
||||||
internal class ContextMenuXamlHost : XamlHostWindow<ContextMenuFlyoutHost>
|
internal class ContextMenuXamlHost : TransparentXamlHost<ContextMenuFlyoutHost>
|
||||||
{
|
{
|
||||||
private Uwp.UI.Controls.NotificationFlyout _flyout;
|
private Uwp.UI.Controls.NotificationFlyout _flyout;
|
||||||
|
|
||||||
+7
-4
@@ -1,15 +1,15 @@
|
|||||||
using NotificationFlyout.Uwp.UI.Controls;
|
using NotificationFlyout.Uwp.UI.Controls;
|
||||||
using NotificationFlyout.Wpf.UI.Extensions;
|
|
||||||
using NotificationFlyout.Uwp.UI.Extensions;
|
using NotificationFlyout.Uwp.UI.Extensions;
|
||||||
|
using NotificationFlyout.Wpf.UI.Extensions;
|
||||||
using NotificationFlyout.Wpf.UI.Helpers;
|
using NotificationFlyout.Wpf.UI.Helpers;
|
||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Windows.UI.Xaml.Controls.Primitives;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Windows.UI.Xaml.Controls.Primitives;
|
||||||
|
|
||||||
namespace NotificationFlyout.Wpf.UI.Controls
|
namespace NotificationFlyout.Wpf.UI.Controls
|
||||||
{
|
{
|
||||||
internal class NotificationFlyoutXamlHost : XamlHostWindow<NotificationFlyoutHost>
|
internal class NotificationFlyoutXamlHost : TransparentXamlHost<NotificationFlyoutHost>
|
||||||
{
|
{
|
||||||
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
private const string ShellTrayHandleName = "Shell_TrayWnd";
|
||||||
|
|
||||||
@@ -176,7 +176,6 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
_notificationIconHelper.SetIcon(icon.Handle);
|
_notificationIconHelper.SetIcon(icon.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void UpdateRequestedTheme()
|
private void UpdateRequestedTheme()
|
||||||
{
|
{
|
||||||
if (_flyout == null) return;
|
if (_flyout == null) return;
|
||||||
@@ -216,24 +215,28 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
|||||||
height = windowHeight;
|
height = windowHeight;
|
||||||
width = windowWidth;
|
width = windowWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TaskbarPosition.Top:
|
case TaskbarPosition.Top:
|
||||||
top = taskbarRect.Bottom;
|
top = taskbarRect.Bottom;
|
||||||
left = FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth;
|
left = FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth;
|
||||||
height = windowHeight;
|
height = windowHeight;
|
||||||
width = windowWidth;
|
width = windowWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TaskbarPosition.Right:
|
case TaskbarPosition.Right:
|
||||||
top = taskbarRect.Bottom - windowHeight;
|
top = taskbarRect.Bottom - windowHeight;
|
||||||
left = taskbarRect.Left - windowWidth;
|
left = taskbarRect.Left - windowWidth;
|
||||||
height = windowHeight;
|
height = windowHeight;
|
||||||
width = windowWidth;
|
width = windowWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TaskbarPosition.Bottom:
|
case TaskbarPosition.Bottom:
|
||||||
top = taskbarRect.Top - windowHeight;
|
top = taskbarRect.Top - windowHeight;
|
||||||
left = FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth;
|
left = FlowDirection == FlowDirection.RightToLeft ? taskbarRect.Left : taskbarRect.Right - windowWidth;
|
||||||
height = windowHeight;
|
height = windowHeight;
|
||||||
width = windowWidth;
|
width = windowWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
||||||
|
using NotificationFlyout.Wpf.UI.Extensions;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Wpf.UI.Controls
|
||||||
|
{
|
||||||
|
internal class TransparentXamlHost<TXamlContent> : XamlHost<TXamlContent> where TXamlContent : Windows.UI.Xaml.UIElement
|
||||||
|
{
|
||||||
|
internal const double WindowSize = 5;
|
||||||
|
|
||||||
|
public TransparentXamlHost()
|
||||||
|
{
|
||||||
|
Loaded += OnLoaded;
|
||||||
|
PrepareDefaultWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WindowsXamlHost OnPreparingXamlHost(WindowsXamlHost xamlHost)
|
||||||
|
{
|
||||||
|
xamlHost.Height = 0;
|
||||||
|
xamlHost.Width = 0;
|
||||||
|
|
||||||
|
return base.OnPreparingXamlHost(xamlHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLoaded(object sender, RoutedEventArgs args)
|
||||||
|
{
|
||||||
|
this.Hidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareDefaultWindow()
|
||||||
|
{
|
||||||
|
ShowInTaskbar = false;
|
||||||
|
ShowActivated = false;
|
||||||
|
WindowStyle = WindowStyle.None;
|
||||||
|
ResizeMode = ResizeMode.NoResize;
|
||||||
|
AllowsTransparency = true;
|
||||||
|
Background = new SolidColorBrush(Colors.Transparent);
|
||||||
|
Height = WindowSize;
|
||||||
|
Width = WindowSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using Microsoft.Toolkit.Wpf.UI.XamlHost;
|
||||||
|
using NotificationFlyout.Wpf.UI.Extensions;
|
||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace NotificationFlyout.Wpf.UI.Controls
|
||||||
|
{
|
||||||
|
internal class XamlHost<TXamlContent> : Window where TXamlContent : Windows.UI.Xaml.UIElement
|
||||||
|
{
|
||||||
|
protected new bool IsLoaded;
|
||||||
|
private WindowsXamlHost _xamlHost;
|
||||||
|
|
||||||
|
public XamlHost()
|
||||||
|
{
|
||||||
|
PrepareWindowsXamlHost();
|
||||||
|
ContentRendered += OnContentRendered;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TXamlContent GetHostContent()
|
||||||
|
{
|
||||||
|
if (_xamlHost == null) return null;
|
||||||
|
return _xamlHost.GetUwpInternalObject() as TXamlContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnContentLoaded()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual WindowsXamlHost OnPreparingXamlHost(WindowsXamlHost xamlHost)
|
||||||
|
{
|
||||||
|
xamlHost.InitialTypeName = typeof(TXamlContent).FullName;
|
||||||
|
xamlHost.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||||
|
xamlHost.VerticalAlignment = VerticalAlignment.Stretch;
|
||||||
|
|
||||||
|
return xamlHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnContentRendered(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
IsLoaded = true;
|
||||||
|
OnContentLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareWindowsXamlHost()
|
||||||
|
{
|
||||||
|
_xamlHost = new WindowsXamlHost();
|
||||||
|
OnPreparingXamlHost(_xamlHost);
|
||||||
|
|
||||||
|
Content = _xamlHost;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user