Introduced a NotificationFlyoutPresenter to allow you to restyle/retemplate the flyout from within your UWP app
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
|
||||
namespace NotificationFlyout.Uwp.UI.Controls
|
||||
{
|
||||
public class NotificationFlyoutHost : Control
|
||||
{
|
||||
public static readonly DependencyProperty FlyoutPresenterProperty =
|
||||
DependencyProperty.Register(nameof(FlyoutPresenter),
|
||||
typeof(NotificationFlyoutPresenter), typeof(NotificationFlyoutHost),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty TemplateSettingsProperty =
|
||||
DependencyProperty.Register(nameof(TemplateSettings),
|
||||
typeof(NotificationFlyoutHostTemplateSettings), typeof(NotificationFlyoutHost),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
private readonly NotificationFlyoutHostTemplateSettings _templateSettings;
|
||||
private Grid _root;
|
||||
|
||||
public NotificationFlyoutHost()
|
||||
{
|
||||
DefaultStyleKey = typeof(NotificationFlyoutHost);
|
||||
|
||||
_templateSettings = new NotificationFlyoutHostTemplateSettings();
|
||||
SetValue(TemplateSettingsProperty, _templateSettings);
|
||||
}
|
||||
|
||||
public NotificationFlyoutPresenter FlyoutPresenter
|
||||
{
|
||||
get => (NotificationFlyoutPresenter)GetValue(FlyoutPresenterProperty);
|
||||
set => SetValue(FlyoutPresenterProperty, value);
|
||||
}
|
||||
|
||||
public NotificationFlyoutHostTemplateSettings TemplateSettings
|
||||
{
|
||||
get => (NotificationFlyoutHostTemplateSettings)GetValue(TemplateSettingsProperty);
|
||||
set => SetValue(TemplateSettingsProperty, value);
|
||||
}
|
||||
|
||||
public void HideFlyout()
|
||||
{
|
||||
if (_root == null) return;
|
||||
FlyoutBase flyout = FlyoutBase.GetAttachedFlyout(_root);
|
||||
flyout.Hide();
|
||||
}
|
||||
|
||||
public void SetOffset(double verticalOffset, double horizontalOffset)
|
||||
{
|
||||
if (_templateSettings == null) return;
|
||||
_templateSettings.FromVerticalOffset = verticalOffset;
|
||||
_templateSettings.FromHorizontalOffset = horizontalOffset;
|
||||
}
|
||||
|
||||
public void ShowFlyout(FlyoutPlacementMode placementMode)
|
||||
{
|
||||
if (_root == null) return;
|
||||
var flyout = FlyoutBase.GetAttachedFlyout(_root);
|
||||
flyout.ShowAt(_root, new FlyoutShowOptions
|
||||
{
|
||||
Placement = placementMode,
|
||||
ShowMode = FlyoutShowMode.Standard
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
_root = GetTemplateChild("Root") as Grid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:NotificationFlyout.Uwp.UI.Controls">
|
||||
<Style TargetType="controls:NotificationFlyoutHost">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:NotificationFlyoutHost">
|
||||
<Grid x:Name="Root">
|
||||
<FlyoutBase.AttachedFlyout>
|
||||
<Flyout AreOpenCloseAnimationsEnabled="False" ShouldConstrainToRootBounds="False">
|
||||
<Flyout.FlyoutPresenterStyle>
|
||||
<Style TargetType="FlyoutPresenter">
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="IsDefaultShadowEnabled" Value="False" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Margin" Value="0" />
|
||||
</Style>
|
||||
</Flyout.FlyoutPresenterStyle>
|
||||
<ContentControl Content="{TemplateBinding FlyoutPresenter}" />
|
||||
</Flyout>
|
||||
</FlyoutBase.AttachedFlyout>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace NotificationFlyout.Uwp.UI.Controls
|
||||
{
|
||||
public class NotificationFlyoutHostTemplateSettings : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty FromHorizontalOffsetProperty =
|
||||
DependencyProperty.Register(nameof(FromHorizontalOffset),
|
||||
typeof(double), typeof(NotificationFlyoutHostTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty FromVerticalOffsetProperty =
|
||||
DependencyProperty.Register(nameof(FromVerticalOffset),
|
||||
typeof(double), typeof(NotificationFlyoutHostTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public double FromHorizontalOffset
|
||||
{
|
||||
get => (double)GetValue(FromHorizontalOffsetProperty);
|
||||
set => SetValue(FromHorizontalOffsetProperty, value);
|
||||
}
|
||||
|
||||
public double FromVerticalOffset
|
||||
{
|
||||
get => (double)GetValue(FromVerticalOffsetProperty);
|
||||
set => SetValue(FromVerticalOffsetProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user