Added API for opening a window from flyout w/ sample

This commit is contained in:
Daniel Clark
2021-02-11 15:09:20 +00:00
parent 0d28dad842
commit 4a6c6ca4a5
12 changed files with 182 additions and 77 deletions
@@ -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;
}
}
}