Added support common styling properties via NotificationFlyout

This commit is contained in:
Daniel Clark
2021-02-12 23:44:52 +00:00
parent 84afcf0be3
commit ee7530b8b5
3 changed files with 46 additions and 22 deletions
@@ -14,38 +14,30 @@ namespace NotificationFlyout.Uwp.UI.Controls
typeof(UIElement), typeof(NotificationFlyoutHost),
new PropertyMetadata(null));
public static readonly DependencyProperty FlyoutPresenterStyleProperty =
DependencyProperty.Register(nameof(FlyoutPresenterStyle),
typeof(Style), typeof(NotificationFlyoutHost),
new PropertyMetadata(null));
private bool _isLoaded;
private string _placement;
private Grid _root;
public NotificationFlyoutHost() => DefaultStyleKey = typeof(NotificationFlyoutHost);
internal void SetOwningFlyout(NotificationFlyout flyout)
{
BindingOperations.SetBinding(this, ContentProperty,
new Binding
{
Source = flyout,
Path =
new PropertyPath(nameof(Content)),
Mode = BindingMode.TwoWay
});
BindingOperations.SetBinding(this, RequestedThemeProperty,
new Binding
{
Source = flyout,
Path = new PropertyPath(nameof(RequestedTheme)),
Mode = BindingMode.TwoWay
});
}
public UIElement Content
{
get => (UIElement)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public Style FlyoutPresenterStyle
{
get => (Style)GetValue(FlyoutPresenterStyleProperty);
set => SetValue(FlyoutPresenterStyleProperty, value);
}
public void HideFlyout()
{
if (_root == null) return;
@@ -75,6 +67,33 @@ namespace NotificationFlyout.Uwp.UI.Controls
});
}
internal void SetOwningFlyout(NotificationFlyout flyout)
{
BindingOperations.SetBinding(this, ContentProperty,
new Binding
{
Source = flyout,
Path =
new PropertyPath(nameof(Content)),
Mode = BindingMode.TwoWay
});
BindingOperations.SetBinding(this, RequestedThemeProperty,
new Binding
{
Source = flyout,
Path = new PropertyPath(nameof(RequestedTheme)),
Mode = BindingMode.TwoWay
});
BindingOperations.SetBinding(this, FlyoutPresenterStyleProperty,
new Binding
{
Source = flyout,
Path = new PropertyPath(nameof(FlyoutPresenterStyle)),
Mode = BindingMode.TwoWay
});
}
protected override void OnApplyTemplate()
{
_root = GetTemplateChild("Root") as Grid;
@@ -54,7 +54,7 @@
FromVerticalOffset="0" />
</TransitionCollection>
</Grid.Transitions>
<controls:NotificationFlyoutPresenter Content="{TemplateBinding Content}" />
<controls:NotificationFlyoutPresenter Content="{TemplateBinding Content}" Style="{TemplateBinding FlyoutPresenterStyle}" />
</Grid>
</Flyout>
</FlyoutBase.AttachedFlyout>