Add zoom slider

This commit is contained in:
Holger Börchers 2022-10-22 17:36:24 +02:00
parent 644e2628e3
commit 14f2a7242a
15 changed files with 141 additions and 101 deletions

View File

@ -0,0 +1,23 @@
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace ModernWpfPlayground;
public class DivideByHundredConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (double)value / 100d;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}

View File

@ -2,12 +2,12 @@
x:Class="ModernWpfPlayground.MainWindow" x:Class="ModernWpfPlayground.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Controls;assembly=Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:ModernWpfPlayground" xmlns:local="clr-namespace:ModernWpfPlayground"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019" xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:controls="clr-namespace:Controls;assembly=Controls"
x:Name="Window" x:Name="Window"
Title="{Binding Title}" Title="{Binding Title}"
Width="{Binding WindowWidth, Mode=TwoWay}" Width="{Binding WindowWidth, Mode=TwoWay}"
@ -27,7 +27,11 @@
<KeyBinding Key="S" Modifiers="Control" /> <KeyBinding Key="S" Modifiers="Control" />
<KeyBinding Key="N" Modifiers="Control" /> <KeyBinding Key="N" Modifiers="Control" />
</Window.InputBindings> </Window.InputBindings>
<Window.Resources>
<ResourceDictionary>
<ScaleTransform x:Key="ZoomSliderScaleTransform" ScaleX="{Binding Value, ElementName=ZoomSlider, Converter={local:DivideByHundredConverter}}" ScaleY="{Binding Value, ElementName=ZoomSlider, Converter={local:DivideByHundredConverter}}" />
</ResourceDictionary>
</Window.Resources>
<DockPanel> <DockPanel>
<!-- TitleBar --> <!-- TitleBar -->
<Grid <Grid
@ -49,6 +53,9 @@
<ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayLeftInset), Converter={local:PixelsToGridLengthConverter}}" /> <ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayLeftInset), Converter={local:PixelsToGridLengthConverter}}" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayRightInset), Converter={local:PixelsToGridLengthConverter}}" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Menu <Menu
Grid.Column="1" Grid.Column="1"
@ -100,12 +107,31 @@
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="13" FontSize="13"
Text="{Binding ElementName=Window, Path=Title}" /> Text="{Binding ElementName=Window, Path=Title}" />
<Slider
x:Name="ZoomSlider"
Grid.Column="3"
Width="150"
AutoToolTipPlacement="TopLeft"
Interval="1"
IsSnapToTickEnabled="True"
Maximum="200"
Minimum="50"
TickFrequency="10"
TickPlacement="BottomRight"
WindowChrome.IsHitTestVisibleInChrome="True"
Value="100" />
<MenuItem
Grid.Column="4"
Click="MenuItem_OnClick"
Header="Reset"
WindowChrome.IsHitTestVisibleInChrome="True" />
</Grid> </Grid>
<!-- Footer --> <!-- Footer -->
<Grid <Grid
Height="24" Height="24"
Background="{DynamicResource SystemControlBackgroundAccentBrush}" Background="{DynamicResource SystemControlBackgroundAccentBrush}"
DockPanel.Dock="Bottom"> DockPanel.Dock="Bottom"
LayoutTransform="{StaticResource ZoomSliderScaleTransform}">
<Grid.Resources> <Grid.Resources>
<Style TargetType="TextBlock"> <Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White" /> <Setter Property="Foreground" Value="White" />
@ -127,7 +153,7 @@
HorizontalAlignment="Right" HorizontalAlignment="Right"
Text="BlaBlaBla" /> Text="BlaBlaBla" />
</Grid> </Grid>
<Grid Row="1"> <Grid LayoutTransform="{StaticResource ZoomSliderScaleTransform}" Row="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="40" /> <ColumnDefinition Width="40" />
<ColumnDefinition /> <ColumnDefinition />
@ -197,7 +223,7 @@
</Grid> </Grid>
</ui:SplitView.Pane> </ui:SplitView.Pane>
<!-- Content --> <!-- Content -->
<TabControl> <TabControl LayoutTransform="{StaticResource ZoomSliderScaleTransform}">
<TabItem Header="Bolt"> <TabItem Header="Bolt">
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True"> <ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True">
<Grid> <Grid>
@ -219,16 +245,9 @@
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
</TabItem> </TabItem>
<TabItem <TabItem Header="General" IsSelected="True">
Header="General"
IsSelected="True">
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True"> <ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True">
<ui:SimpleStackPanel Margin="5" Spacing="10"> <ui:SimpleStackPanel Margin="5" Spacing="10">
<ComboBox
DisplayMemberPath="Key"
ItemsSource="{Binding ThemeMode, Converter={controls:EnumToItemSourceConverter}}"
SelectedValue="{Binding ThemeMode}"
SelectedValuePath="Value" />
<controls:PropertyPresenter Label="Theme Mode" Value="{Binding ThemeMode}" /> <controls:PropertyPresenter Label="Theme Mode" Value="{Binding ThemeMode}" />
<controls:PropertyPresenter Label="Accent color" Value="{Binding AccentColors}" /> <controls:PropertyPresenter Label="Accent color" Value="{Binding AccentColors}" />
<controls:PropertyPresenter <controls:PropertyPresenter

View File

@ -1,4 +1,7 @@
namespace ModernWpfPlayground using System.Windows;
using System.Windows.Controls.Primitives;
namespace ModernWpfPlayground
{ {
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
@ -9,5 +12,10 @@
{ {
InitializeComponent(); InitializeComponent();
} }
private void MenuItem_OnClick(object sender, RoutedEventArgs e)
{
ZoomSlider.Value = 100;
}
} }
} }

View File

@ -1,62 +1,62 @@
using System.Windows; using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ModernWpfPlayground.Types; using ModernWpfPlayground.Types;
using MvvmGen;
using static ModernWpf.ThemeManager; using static ModernWpf.ThemeManager;
namespace ModernWpfPlayground namespace ModernWpfPlayground
{ {
// ReSharper disable once ClassNeverInstantiated.Global // ReSharper disable once ClassNeverInstantiated.Global
[ViewModel] public partial class MainWindowViewModel : ObservableObject
public partial class MainWindowViewModel
{ {
private const string AppName = "TaBEA 3.0.0"; private const string AppName = "TaBEA 3.0.0";
[Property, PropertyCallMethod(nameof(SetTitle))] [ObservableProperty] private string? _path;
private string? _path; [ObservableProperty] private string _title = AppName;
[ObservableProperty] private bool _booleanValue = true;
[ObservableProperty] private Visibility _visibilityEnumTest = Visibility.Visible;
[ObservableProperty] private double _sliderTest = 100;
[ObservableProperty] private double _validationTest;
[ObservableProperty] private string? _welcomeMessage = "Shadow of the empire";
[ObservableProperty] private ThemeMode _themeMode = ThemeMode.UseSystemSetting;
[ObservableProperty] private AccentColors _accentColors = AccentColors.Green;
[ObservableProperty] private int _windowWidth = 1200;
[ObservableProperty] private int _windowHeight = 600;
[ObservableProperty] private bool _isPaneOpen = true;
[Property] private string _title = AppName; partial void OnBooleanValueChanged(bool value)
{
VisibilityEnumTest = value ? Visibility.Visible : Visibility.Collapsed;
}
[Property, PropertyCallMethod(nameof(BooleanValue_OnChanged))] partial void OnPathChanged(string? value)
private bool _booleanValue = true; {
Title = value != null ? $"{System.IO.Path.GetFileName(value)} - {AppName}" : AppName;
[Property] private Visibility _visibilityEnumTest = Visibility.Visible; }
[Property] private double _sliderTest = 100;
[Property] private double _validationTest;
[Property] private string? _welcomeMessage = "Shadow of the empire";
[Property, PropertyCallMethod(nameof(SetTheme))]
private ThemeMode _themeMode = ThemeMode.UseSystemSetting;
[Property, PropertyCallMethod(nameof(SetAccentColor))]
private AccentColors _accentColors = AccentColors.Green;
[Property] private int _windowWidth = 1200;
[Property] private int _windowHeight = 600;
[Property] private bool _isPaneOpen = true;
[Command] [RelayCommand]
private void ShowNotification() private void ShowNotification()
{ {
} }
[Command] [RelayCommand]
private void Close() private void Close()
{ {
Application.Current.MainWindow?.Close(); Application.Current.MainWindow?.Close();
} }
private void SetTitle() partial void OnThemeModeChanged(ThemeMode value)
{ {
Title = Path != null ? $"{System.IO.Path.GetFileName(Path)} - {AppName}" : AppName; Current.ApplicationTheme = value.ToApplicationTheme();
} }
private void SetAccentColor() => Current.AccentColor = AccentColors.ToWindowsColor(); partial void OnAccentColorsChanged(AccentColors value)
{
Current.AccentColor = value.ToWindowsColor();
}
[RelayCommand]
private void SetTheme() => Current.ApplicationTheme = ThemeMode.ToApplicationTheme();
[Command]
private async void ShowDialog() private async void ShowDialog()
{ {
var dialog = new ContentDialogExample { Message = WelcomeMessage }; var dialog = new ContentDialogExample { Message = WelcomeMessage };
@ -64,12 +64,7 @@ namespace ModernWpfPlayground
WelcomeMessage = result.ToString(); WelcomeMessage = result.ToString();
} }
private void BooleanValue_OnChanged() [RelayCommand]
{
VisibilityEnumTest = BooleanValue ? Visibility.Visible : Visibility.Collapsed;
}
[Command]
private void SaveViewModel() private void SaveViewModel()
{ {
// var contents = _serializer.Serialize(Values); // var contents = _serializer.Serialize(Values);

View File

@ -2,7 +2,8 @@
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
@ -12,10 +13,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
<PackageReference Include="FastMember" Version="1.5.0" /> <PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" /> <PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="ModernWpfUI" Version="0.9.7-preview.2" /> <PackageReference Include="ModernWpfUI" Version="0.9.7-preview.2" />
<PackageReference Include="MvvmGen" Version="1.1.5" />
<PackageReference Include="YamlDotNet" Version="12.0.2" /> <PackageReference Include="YamlDotNet" Version="12.0.2" />
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.11.0" /> <PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.11.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,5 +1,4 @@
using System; using System.Globalization;
using System.Globalization;
using System.Windows; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Markup; using System.Windows.Markup;

View File

@ -1,5 +1,4 @@
using System; using System.Windows.Media;
using System.Windows.Media;
namespace ModernWpfPlayground.Types; namespace ModernWpfPlayground.Types;

View File

@ -1,5 +1,4 @@
using System; using System.ComponentModel;
using System.ComponentModel;
using ModernWpf; using ModernWpf;
namespace ModernWpfPlayground.Types namespace ModernWpfPlayground.Types

View File

@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=propertypresenter/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Markup; using System.Windows.Markup;

View File

@ -1,6 +1,4 @@
using System; using System.Globalization;
using System.Collections.Generic;
using System.Globalization;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

View File

@ -1,5 +1,4 @@
using System; using System.Windows;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
namespace Controls; namespace Controls;

View File

@ -15,6 +15,7 @@
</Validation.ErrorTemplate> </Validation.ErrorTemplate>
<ContentControl.Resources> <ContentControl.Resources>
<DataTemplate x:Key="DefaultDataTemplate"> <DataTemplate x:Key="DefaultDataTemplate">
<Grid>
<Grid> <Grid>
<controls:TextBoxEx <controls:TextBoxEx
x:Name="InputTextBox" x:Name="InputTextBox"
@ -39,6 +40,13 @@
</Style> </Style>
</TextBox.Style> </TextBox.Style>
</controls:TextBoxEx> </controls:TextBoxEx>
<controls:MagicSymbolControl
x:Name="PartSymbol"
Margin="5,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Symbol="{Binding Symbol, ElementName=LayoutRoot}" />
</Grid>
<TextBlock <TextBlock
Margin="6,0,0,0" Margin="6,0,0,0"
Padding="2,2,2,2" Padding="2,2,2,2"
@ -152,13 +160,6 @@
VerticalAlignment="Center" VerticalAlignment="Center"
Focusable="False" Focusable="False"
Text="{Binding Label, ElementName=LayoutRoot}" /> Text="{Binding Label, ElementName=LayoutRoot}" />
<controls:MagicSymbolControl
x:Name="PartSymbol"
Grid.Column="2"
Margin="5,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Symbol="{Binding Symbol, ElementName=LayoutRoot}" />
</Grid> </Grid>
<DockPanel Grid.Column="1"> <DockPanel Grid.Column="1">
<Button <Button

View File

@ -1,5 +1,4 @@
using System; using System.Drawing;
using System.Drawing;
using System.Globalization; using System.Globalization;
using System.Net; using System.Net;
using System.Windows; using System.Windows;