Skip to content

Commit

Permalink
Add WindowExample
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Apr 7, 2024
1 parent 31dd752 commit 059f75c
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 4 deletions.
15 changes: 15 additions & 0 deletions WindowExample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Application x:Class="WindowExample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WindowExample"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources/>
<ui:XamlControlsResources />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
14 changes: 14 additions & 0 deletions WindowExample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace WindowExample
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions WindowExample/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
95 changes: 95 additions & 0 deletions WindowExample/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<Window x:Class="WindowExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:local="clr-namespace:WindowExample" xmlns:sys="clr-namespace:System;assembly=netstandard"
mc:Ignorable="d"
ui:WindowHelper.UseModernWindowStyle="True" ui:TitleBar.Height="36"
FontSize="14"
Title="MainWindow" Height="540" Width="800">
<FrameworkElement.Resources>
<ResourceDictionary>

<Style x:Key="TitleBarButtonAvailabilitySelector" TargetType="ComboBox" BasedOn="{StaticResource {x:Static ui:ThemeKeys.DefaultComboBoxStyleKey}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Grid.Row" Value="2"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<EventSetter Event="Loaded" Handler="TitleBarButtonAvailabilitySelector_Loaded"/>
<EventSetter Event="SelectionChanged" Handler="TitleBarButtonAvailabilitySelector_SelectionChanged"/>
</Style>

</ResourceDictionary>
</FrameworkElement.Resources>
<ui:SimpleStackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="20">
<TextBlock Text="Window Example" FontWeight="Bold" FontSize="24" TextAlignment="Center"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Text="WindowStyle" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="0" Grid.Column="1" Spacing="8" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_WindowStyle_None" Content="None" MinWidth="0" Click="RadioButton_WindowStyle_Click"/>
<RadioButton x:Name="RadioButton_WindowStyle_SingleBorder" Content="SingleBorder" MinWidth="0" IsChecked="True" Click="RadioButton_WindowStyle_Click"/>
<RadioButton x:Name="RadioButton_WindowStyle_ThreeDBorder" Content="ThreeDBorder" MinWidth="0" Click="RadioButton_WindowStyle_Click"/>
<RadioButton x:Name="RadioButton_WindowStyle_Tool" Content="Tool" MinWidth="0" Click="RadioButton_WindowStyle_Click"/>
</ui:SimpleStackPanel>

<TextBlock Text="ResizeMode" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="1" Grid.Column="1" Spacing="4" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_ResizeMode_NoResize" Content="NoResize" MinWidth="0" Click="RadioButton_ResizeMode_Click"/>
<RadioButton x:Name="RadioButton_ResizeMode_CanMinimize" Content="CanMinimize" MinWidth="0" Click="RadioButton_ResizeMode_Click"/>
<RadioButton x:Name="RadioButton_ResizeMode_CanResize" Content="CanResize" MinWidth="0" IsChecked="True" Click="RadioButton_ResizeMode_Click"/>
<RadioButton x:Name="RadioButton_ResizeMode_CanResizeWithGrip" Content="CanResizeWithGrip" MinWidth="0" Click="RadioButton_ResizeMode_Click"/>
</ui:SimpleStackPanel>

<TextBlock Text="(ui) BackdropType" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10"/>
<ui:SimpleStackPanel Grid.Row="2" Grid.Column="1" Spacing="8" Orientation="Horizontal">
<RadioButton x:Name="RadioButton_SystemBackdropType_Acrylic" Content="Acrylic" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_Mica" Content="Mica" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_None" Content="None" MinWidth="0" IsChecked="True" Click="RadioButton_SystemBackdropType_Click"/>
<RadioButton x:Name="RadioButton_SystemBackdropType_Tabbed" Content="Tabbed" MinWidth="0" Click="RadioButton_SystemBackdropType_Click"/>
</ui:SimpleStackPanel>

<ui:SimpleStackPanel Grid.Row="3" Grid.ColumnSpan="2" Spacing="10" Orientation="Horizontal" Margin="10">
<CheckBox x:Name="CheckBox_UseModernWindowStyle" Content="(ui) ModernStyle" IsChecked="True" IsEnabled="False" Click="CheckBox_UseModernWindowStyle_Click"/>
<CheckBox x:Name="CheckBox_ApplyBackground" Content="(ui) ApplyBackground" IsChecked="False" Click="CheckBox_ApplyBackground_Click"/>
<CheckBox x:Name="CheckBox_ApplyNoise" Content="(ui) ApplyNoise" IsChecked="False" Click="CheckBox_ApplyNoise_Click"/>
</ui:SimpleStackPanel>

<Grid Grid.Row="4" Grid.ColumnSpan="2" Margin="6">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Text="Minimize button" Grid.Column="0" Margin="4"/>
<ComboBox x:Name="ComboBox_TitleBarButtonMinimizeAvailability_Minimize" Grid.Column="0" Tag="{x:Static ui:TitleBar.ButtonMinimizeAvailabilityProperty}" Style="{StaticResource TitleBarButtonAvailabilitySelector}"/>

<TextBlock Text="Maximize button" Grid.Column="1" Margin="4"/>
<ComboBox x:Name="ComboBox_TitleBarButtonMaximizeAvailability_Minimize" Grid.Column="1" Tag="{x:Static ui:TitleBar.ButtonMaximizeAvailabilityProperty}" Style="{StaticResource TitleBarButtonAvailabilitySelector}"/>

<TextBlock Text="Close button" Grid.Column="2" Margin="4"/>
<ComboBox x:Name="ComboBox_TitleBarButtonCloseAvailability_Minimize" Grid.Column="2" Tag="{x:Static ui:TitleBar.ButtonCloseAvailabilityProperty}" Style="{StaticResource TitleBarButtonAvailabilitySelector}"/>


</Grid>

</Grid>
</ui:SimpleStackPanel>
</Window>
127 changes: 127 additions & 0 deletions WindowExample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using iNKORE.UI.WPF.Modern.Controls.Helpers;
using iNKORE.UI.WPF.Modern.Controls.Primitives;
using iNKORE.UI.WPF.Modern.Helpers.Styles;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WindowExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void RadioButton_WindowStyle_Click(object sender, RoutedEventArgs e)
{
if (sender is RadioButton btn && btn.Content is string val)
{
try
{
this.WindowStyle = (WindowStyle)Enum.Parse(typeof(WindowStyle), val);
}
catch
{
try
{
this.WindowStyle = (WindowStyle)Enum.Parse(typeof(WindowStyle), val + "Window");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

private void RadioButton_ResizeMode_Click(object sender, RoutedEventArgs e)
{
if (sender is RadioButton btn && btn.Content is string val)
{
try
{
this.ResizeMode = (ResizeMode)Enum.Parse(typeof(ResizeMode), val);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}

private void CheckBox_UseModernWindowStyle_Click(object sender, RoutedEventArgs e)
{
WindowHelper.SetUseModernWindowStyle(this, CheckBox_UseModernWindowStyle.IsChecked ?? false);
}

private void RadioButton_SystemBackdropType_Click(object sender, RoutedEventArgs e)
{
if (sender is RadioButton btn && btn.Content is string val)
{
try
{
WindowHelper.SetSystemBackdropType(this, (BackdropType)Enum.Parse(typeof(BackdropType), val));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

}

private void CheckBox_ApplyBackground_Click(object sender, RoutedEventArgs e)
{
WindowHelper.SetApplyBackground(this, CheckBox_ApplyBackground.IsChecked ?? false);
}

private void CheckBox_ApplyNoise_Click(object sender, RoutedEventArgs e)
{
WindowHelper.SetApplyNoise(this, CheckBox_ApplyBackground.IsChecked ?? false);
}

private void TitleBarButtonAvailabilitySelector_Loaded(object sender, RoutedEventArgs e)
{
if(sender is ComboBox comboBox)
{
comboBox.ItemsSource = new string[]
{
"Auto",
"Collapsed",
"Disabled",
"Enabled"
};

comboBox.SelectedIndex = 0;
}
}

private void TitleBarButtonAvailabilitySelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(sender is ComboBox box && box.Tag is DependencyProperty prop && box.SelectedItem is string val)
{
try
{
this.SetValue(prop, (TitleBarButtonAvailability)Enum.Parse(typeof(TitleBarButtonAvailability), val));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
}
15 changes: 15 additions & 0 deletions WindowExample/WindowExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\source\Inkore.UI.WPF.Modern\iNKORE.UI.WPF.Modern.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions iNKORE.UI.WPF.Modern.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StarterKit", "source\sample
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsPageExample", "source\samples\SettingsPageExample\SettingsPageExample.csproj", "{677DAAFA-C061-4C79-BAAE-5639BCD80448}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowExample", "WindowExample\WindowExample.csproj", "{936F7656-B5E8-44A8-8560-D954E1E68383}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -261,6 +263,26 @@ Global
{677DAAFA-C061-4C79-BAAE-5639BCD80448}.Release|x64.Build.0 = Release|Any CPU
{677DAAFA-C061-4C79-BAAE-5639BCD80448}.Release|x86.ActiveCfg = Release|Any CPU
{677DAAFA-C061-4C79-BAAE-5639BCD80448}.Release|x86.Build.0 = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|Any CPU.Build.0 = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM.ActiveCfg = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM.Build.0 = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|ARM64.Build.0 = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x64.ActiveCfg = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x64.Build.0 = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x86.ActiveCfg = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Debug|x86.Build.0 = Debug|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|Any CPU.ActiveCfg = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|Any CPU.Build.0 = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM.ActiveCfg = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM.Build.0 = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM64.ActiveCfg = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|ARM64.Build.0 = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x64.ActiveCfg = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x64.Build.0 = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x86.ActiveCfg = Release|Any CPU
{936F7656-B5E8-44A8-8560-D954E1E68383}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -275,6 +297,7 @@ Global
{3614991C-ECC0-474A-BC8E-1D0A56FD0BDE} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128}
{B13E16CB-55E0-42CB-B761-216D82273473} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128}
{677DAAFA-C061-4C79-BAAE-5639BCD80448} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128}
{936F7656-B5E8-44A8-8560-D954E1E68383} = {A96F98E9-18B5-4863-8F28-9B7BDF70A128}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6251E140-0FAA-4DE9-B245-1C5BE188E578}
Expand Down
27 changes: 23 additions & 4 deletions source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public void RefreshButtonActualAvailabilities()
}
}


InitializeSnapLayout();
}


Expand All @@ -631,7 +631,7 @@ private void OnRightSystemOverlaySizeChanged(object sender, SizeChangedEventArgs

private void OnMaximizeRestoreButtonLoaded(object sender, RoutedEventArgs e)
{
InitializeSnapLayout(MaximizeRestoreButton);
InitializeSnapLayout();
}

private void UpdateSystemOverlayLeftInset(double value)
Expand All @@ -652,12 +652,31 @@ private void UpdateSystemOverlayRightInset(double value)
}
}

private void InitializeSnapLayout()
{
if(MaximizeRestoreButton != null)
{
InitializeSnapLayout(MaximizeRestoreButton);
}
}

private void InitializeSnapLayout(TitleBarButton maximizeButton)
{
if (!SnapLayout.IsSupported) return;

_snapLayout = new SnapLayout();
_snapLayout.Register(maximizeButton);
if (maximizeButton.IsEnabled && maximizeButton.Visibility == Visibility.Visible)
{
_snapLayout = new SnapLayout();
_snapLayout.Register(maximizeButton);
}
else
{
if(_snapLayout != null)
{
_snapLayout.Unregister();
_snapLayout = null;
}
}
}

private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e)
Expand Down
Loading

0 comments on commit 059f75c

Please sign in to comment.