Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves UpbeatMainWindow fullscreen view capabilities #33

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions samples/HostedUpbeatUISample/View/MenuTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<Button
Command="{Binding OpenSharedListCommand}"
Margin="5">Shared List</Button>
<ToggleButton
IsChecked="{Binding Fullscreen, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type uv:UpbeatMainWindow}}}"
Margin="5">Fullscreen</ToggleButton>
<TextBlock
TextAlignment="Center"
Margin="5"
Expand Down
3 changes: 3 additions & 0 deletions samples/ManualUpbeatUISample/View/MenuTemplate.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<Button
Command="{Binding OpenSharedListCommand}"
Margin="5">Shared List</Button>
<ToggleButton
IsChecked="{Binding Fullscreen, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type uv:UpbeatMainWindow}}}"
Margin="5">Fullscreen</ToggleButton>
<TextBlock
TextAlignment="Center"
Margin="5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<Button
Command="{Binding OpenSharedListCommand}"
Margin="5">Shared List</Button>
<ToggleButton
IsChecked="{Binding Fullscreen, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type uv:UpbeatMainWindow}}}"
Margin="5">Fullscreen</ToggleButton>
<TextBlock
TextAlignment="Center"
Margin="5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<Copyright>© Michael P. Duda 2020-2024</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- Update the following properties when publishing a new Nuget version -->
<Version>2.2.0-rc1</Version>
<Version>2.2.0-rc2</Version>
<PackageValidationBaselineVersion>2.1.0</PackageValidationBaselineVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<Copyright>© Michael P. Duda 2020-2024</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- Update the following properties when publishing a new Nuget version -->
<Version>4.2.0-rc1</Version>
<Version>4.2.0-rc2</Version>
<PackageValidationBaselineVersion>4.1.0</PackageValidationBaselineVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion source/UpbeatUI/UpbeatUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Copyright>© Michael P. Duda 2020-2024</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<!-- Update the following properties when publishing a new Nuget version -->
<Version>5.2.0-rc1</Version>
<Version>5.2.0-rc2</Version>
<PackageValidationBaselineVersion>5.1.0</PackageValidationBaselineVersion>
</PropertyGroup>

Expand Down
17 changes: 3 additions & 14 deletions source/UpbeatUI/View/UpbeatMainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,11 @@
Property="Margin"
Value="0" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition
Binding="{Binding ElementName=_upbeatMainWindow, Path=ResizeMode}"
Value="NoResize" />
<Condition
Binding="{Binding ElementName=_upbeatMainWindow, Path=WindowState}"
Value="Maximized" />
<Condition
Binding="{Binding ElementName=_upbeatMainWindow, Path=WindowStyle}"
Value="None" />
</MultiDataTrigger.Conditions>
<DataTrigger Binding="{Binding Fullscreen, ElementName=_upbeatMainWindow}" Value="True">
<Setter
Property="Margin"
Value="8" />
</MultiDataTrigger>
Value="{Binding FullscreenContentMargin, ElementName=_upbeatMainWindow}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
Expand Down
59 changes: 59 additions & 0 deletions source/UpbeatUI/View/UpbeatMainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ namespace UpbeatUI.View
/// </summary>
public partial class UpbeatMainWindow : Window
{
/// <summary>
/// Identifies the <see cref="Fullscreen"/> <see cref="DependencyProperty"/>.
/// </summary>
public readonly static DependencyProperty FullscreenProperty =
DependencyProperty.Register(
"Fullscreen",
typeof(bool),
typeof(UpbeatMainWindow),
new FrameworkPropertyMetadata(false, HandleFullscreenPropertyChanged));

/// <summary>
/// Identifies the <see cref="FullscreenContentMargin"/> <see cref="DependencyProperty"/>.
/// </summary>
public readonly static DependencyProperty FullscreenContentMarginProperty =
DependencyProperty.Register(
"FullscreenContentMargin",
typeof(Thickness),
typeof(UpbeatMainWindow),
new FrameworkPropertyMetadata(new Thickness(0)));

/// <summary>
/// Identifies the <see cref="ModalBackground"/> <see cref="DependencyProperty"/>.
/// </summary>
Expand All @@ -35,6 +55,26 @@ public partial class UpbeatMainWindow : Window
public UpbeatMainWindow() =>
InitializeComponent();

/// <summary>
/// Gets or sets whether the <see cref="UpbeatMainWindow"/> is in fullscreen mode or not.
/// </summary>
public bool Fullscreen
{
get => (bool)GetValue(FullscreenProperty);
set => SetValue(FullscreenProperty, value);
}

/// <summary>
/// Gets or sets the <see cref="UpbeatMainWindow"/>'s content margin when in fullscreen mode.
/// <para>Under certain <see cref="Window"/> styling conditions and when in fullscreen mode, the content might be rendered outside the visible area of the screen. This property allows you to counteract that behavior by adding margin to the content to shrink its rendered size (or subtracting margin to increase the rendered size).</para>
/// <para>This property has no effect when in windowed (non-fullscreen) mode.</para>
/// </summary>
public Thickness FullscreenContentMargin
{
get => (Thickness)GetValue(FullscreenContentMarginProperty);
set => SetValue(FullscreenContentMarginProperty, value);
}

/// <summary>
/// Gets or sets a <see cref="Brush"/> that the <see cref="ModalPanel"/> will show underneath the top (active) Element.
/// </summary>
Expand All @@ -52,5 +92,24 @@ public BlurEffect ModalBlurEffect
get => (BlurEffect)GetValue(ModalBlurEffectProprety);
set => SetValue(ModalBlurEffectProprety, value);
}

private static void HandleFullscreenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is UpbeatMainWindow upbeatMainWindow)
{
if (upbeatMainWindow.Fullscreen)
{
upbeatMainWindow.ResizeMode = ResizeMode.NoResize;
upbeatMainWindow.WindowStyle = WindowStyle.None;
upbeatMainWindow.WindowState = WindowState.Maximized;
}
else
{
upbeatMainWindow.WindowState = WindowState.Normal;
upbeatMainWindow.WindowStyle = WindowStyle.SingleBorderWindow;
upbeatMainWindow.ResizeMode = ResizeMode.CanResize;
}
}
}
}
}