project
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup.Flyout.Controls
|
||||
{
|
||||
public class TaskbarButtonFlyout : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty TemplateSettingsProperty =
|
||||
DependencyProperty.Register(nameof(TemplateSettings),
|
||||
typeof(TaskbarButtonFlyoutTemplateSettings), typeof(TaskbarButtonFlyout),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
private UIElement child;
|
||||
private Border container;
|
||||
|
||||
public TaskbarButtonFlyout()
|
||||
{
|
||||
DefaultStyleKey = typeof(TaskbarButtonFlyout);
|
||||
TemplateSettings = new TaskbarButtonFlyoutTemplateSettings();
|
||||
}
|
||||
|
||||
public event EventHandler<object> Closed;
|
||||
|
||||
public event EventHandler<object> Opened;
|
||||
|
||||
public TaskbarButtonFlyoutTemplateSettings TemplateSettings
|
||||
{
|
||||
get => (TaskbarButtonFlyoutTemplateSettings)GetValue(TemplateSettingsProperty);
|
||||
set => SetValue(TemplateSettingsProperty, value);
|
||||
}
|
||||
|
||||
public bool IsOpen { get; private set; }
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if(container is not null)
|
||||
{
|
||||
container.Child = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
container = GetTemplateChild("Container") as Border;
|
||||
if (container != null)
|
||||
{
|
||||
child = container.Child;
|
||||
container.Child = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowAt(TaskbarButtonFlyoutPlacement taskbarPlacement)
|
||||
{
|
||||
VisualStateManager.GoToState(this, "DefaultPlacement", true);
|
||||
|
||||
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
|
||||
var width = child.DesiredSize.Width - 1;
|
||||
var height = child.DesiredSize.Height - 1;
|
||||
|
||||
TemplateSettings.SetValue(TaskbarButtonFlyoutTemplateSettings.HeightProperty, height);
|
||||
TemplateSettings.SetValue(TaskbarButtonFlyoutTemplateSettings.WidthProperty, width);
|
||||
|
||||
TemplateSettings.SetValue(TaskbarButtonFlyoutTemplateSettings.NegativeHeightProperty, -height);
|
||||
TemplateSettings.SetValue(TaskbarButtonFlyoutTemplateSettings.NegativeWidthProperty, -width);
|
||||
|
||||
VisualStateManager.GoToState(this, $"{taskbarPlacement}Placement", true);
|
||||
|
||||
container.Child = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:TheXamlGuy.TaskbarGroup.Flyout.Controls">
|
||||
<ResourceDictionary.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Default">
|
||||
<AcrylicBrush
|
||||
x:Key="AcrylicBackgroundFillColorBrush"
|
||||
BackgroundSource="HostBackdrop"
|
||||
FallbackColor="#2C2C2C"
|
||||
TintColor="#2C2C2C"
|
||||
TintOpacity="0.8" />
|
||||
<StaticResource x:Key="TaskbarButtonFlyoutBorderBrush" ResourceKey="SurfaceStrokeColorDefaultBrush" />
|
||||
<StaticResource x:Key="TaskbarButtonFlyoutBackgroundBrush" ResourceKey="AcrylicBackgroundFillColorBrush" />
|
||||
<Thickness x:Key="TaskbarButtonFlyoutBorderWidth">1</Thickness>
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary x:Key="Light">
|
||||
<AcrylicBrush
|
||||
x:Key="AcrylicBackgroundFillColorBrush"
|
||||
BackgroundSource="HostBackdrop"
|
||||
FallbackColor="#F9F9F9"
|
||||
TintColor="#FCFCFC"
|
||||
TintOpacity="0.8" />
|
||||
<StaticResource x:Key="TaskbarButtonFlyoutBorderBrush" ResourceKey="SurfaceStrokeColorDefaultBrush" />
|
||||
<StaticResource x:Key="TaskbarButtonFlyoutBackgroundBrush" ResourceKey="AcrylicBackgroundFillColorBrush" />
|
||||
<Thickness x:Key="TaskbarButtonFlyoutBorderWidth">1</Thickness>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
<AcrylicBrush
|
||||
x:Key="NotificationFlyoutPresenterBackgroundAccentBrush"
|
||||
BackgroundSource="HostBackdrop"
|
||||
FallbackColor="{ThemeResource SystemAccentColorDark1}"
|
||||
TintColor="{ThemeResource SystemAccentColorDark1}"
|
||||
TintOpacity="0.8" />
|
||||
<Style TargetType="controls:TaskbarButtonFlyout">
|
||||
<Setter Property="BorderThickness" Value="{ThemeResource TaskbarButtonFlyoutBorderWidth}" />
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource TaskbarButtonFlyoutBorderBrush}" />
|
||||
<Setter Property="Background" Value="{ThemeResource TaskbarButtonFlyoutBackgroundBrush}" />
|
||||
<Setter Property="CornerRadius" Value="{ThemeResource OverlayCornerRadius}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:TaskbarButtonFlyout">
|
||||
<Border x:Name="Container" Margin="{TemplateBinding Margin}">
|
||||
<Grid x:Name="LayoutRoot">
|
||||
<Border
|
||||
x:Name="BackgroundElement"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{TemplateBinding Background}"
|
||||
BackgroundSizing="OuterBorderEdge"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Border.Transitions>
|
||||
<TransitionCollection>
|
||||
<EntranceThemeTransition x:Name="EntranceThemeTransition" />
|
||||
</TransitionCollection>
|
||||
</Border.Transitions>
|
||||
<Grid>
|
||||
<ContentControl
|
||||
x:Name="ContentPresenter"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="PlacementStates">
|
||||
<VisualState x:Name="DefaultPlacement" />
|
||||
<VisualState x:Name="BottomPlacement">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="0" />
|
||||
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.Height}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="TopPlacement">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="0" />
|
||||
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeHeight}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="LeftPlacement">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeWidth}" />
|
||||
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="0" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="RightPlacement">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="EntranceThemeTransition.FromHorizontalOffset" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.Width}" />
|
||||
<Setter Target="EntranceThemeTransition.FromVerticalOffset" Value="0" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup x:Name="ThemeStates">
|
||||
<VisualState x:Name="DefaultTheme" />
|
||||
<VisualState x:Name="ColorPrevalenceTheme">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="BackgroundElement.Background" Value="{ThemeResource TaskbarButtonFlyoutPresenterBackgroundBrush}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace TheXamlGuy.TaskbarGroup.Flyout.Controls
|
||||
{
|
||||
public enum TaskbarButtonFlyoutPlacement
|
||||
{
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using Windows.UI.Xaml;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup.Flyout.Controls
|
||||
{
|
||||
public class TaskbarButtonFlyoutTemplateSettings : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty HeightProperty =
|
||||
DependencyProperty.Register(nameof(Height),
|
||||
typeof(double), typeof(TaskbarButtonFlyoutTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty NegativeHeightProperty =
|
||||
DependencyProperty.Register(nameof(NegativeHeight),
|
||||
typeof(double), typeof(TaskbarButtonFlyoutTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty NegativeWidthProperty =
|
||||
DependencyProperty.Register(nameof(NegativeWidth),
|
||||
typeof(double), typeof(TaskbarButtonFlyoutTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty WidthProperty =
|
||||
DependencyProperty.Register(nameof(Width),
|
||||
typeof(double), typeof(TaskbarButtonFlyoutTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public double Height
|
||||
{
|
||||
get => (double)GetValue(HeightProperty);
|
||||
set => SetValue(HeightProperty, value);
|
||||
}
|
||||
public double NegativeHeight
|
||||
{
|
||||
get => (double)GetValue(NegativeHeightProperty);
|
||||
set => SetValue(NegativeHeightProperty, value);
|
||||
}
|
||||
|
||||
public double NegativeWidth
|
||||
{
|
||||
get => (double)GetValue(NegativeWidthProperty);
|
||||
set => SetValue(NegativeWidthProperty, value);
|
||||
}
|
||||
|
||||
public double Width
|
||||
{
|
||||
get => (double)GetValue(WidthProperty);
|
||||
set => SetValue(WidthProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user