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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:local="clr-namespace:ModernWpfPlayground"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:controls="clr-namespace:Controls;assembly=Controls"
x:Name="Window"
Title="{Binding Title}"
Width="{Binding WindowWidth, Mode=TwoWay}"
@ -27,7 +27,11 @@
<KeyBinding Key="S" Modifiers="Control" />
<KeyBinding Key="N" Modifiers="Control" />
</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>
<!-- TitleBar -->
<Grid
@ -49,6 +53,9 @@
<ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayLeftInset), Converter={local:PixelsToGridLengthConverter}}" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayRightInset), Converter={local:PixelsToGridLengthConverter}}" />
</Grid.ColumnDefinitions>
<Menu
Grid.Column="1"
@ -100,12 +107,31 @@
VerticalAlignment="Center"
FontSize="13"
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>
<!-- Footer -->
<Grid
Height="24"
Background="{DynamicResource SystemControlBackgroundAccentBrush}"
DockPanel.Dock="Bottom">
DockPanel.Dock="Bottom"
LayoutTransform="{StaticResource ZoomSliderScaleTransform}">
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
@ -127,7 +153,7 @@
HorizontalAlignment="Right"
Text="BlaBlaBla" />
</Grid>
<Grid Row="1">
<Grid LayoutTransform="{StaticResource ZoomSliderScaleTransform}" Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition />
@ -197,7 +223,7 @@
</Grid>
</ui:SplitView.Pane>
<!-- Content -->
<TabControl>
<TabControl LayoutTransform="{StaticResource ZoomSliderScaleTransform}">
<TabItem Header="Bolt">
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True">
<Grid>
@ -219,16 +245,9 @@
</Grid>
</ScrollViewer>
</TabItem>
<TabItem
Header="General"
IsSelected="True">
<TabItem Header="General" IsSelected="True">
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True">
<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="Accent color" Value="{Binding AccentColors}" />
<controls:PropertyPresenter

View File

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

View File

@ -1,62 +1,62 @@
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using ModernWpfPlayground.Types;
using MvvmGen;
using static ModernWpf.ThemeManager;
namespace ModernWpfPlayground
{
// ReSharper disable once ClassNeverInstantiated.Global
[ViewModel]
public partial class MainWindowViewModel
public partial class MainWindowViewModel : ObservableObject
{
private const string AppName = "TaBEA 3.0.0";
[Property, PropertyCallMethod(nameof(SetTitle))]
private string? _path;
[ObservableProperty] 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))]
private bool _booleanValue = true;
[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;
partial void OnPathChanged(string? value)
{
Title = value != null ? $"{System.IO.Path.GetFileName(value)} - {AppName}" : AppName;
}
[Command]
[RelayCommand]
private void ShowNotification()
{
}
[Command]
[RelayCommand]
private void 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();
}
private void SetTheme() => Current.ApplicationTheme = ThemeMode.ToApplicationTheme();
[Command]
[RelayCommand]
private async void ShowDialog()
{
var dialog = new ContentDialogExample { Message = WelcomeMessage };
@ -64,12 +64,7 @@ namespace ModernWpfPlayground
WelcomeMessage = result.ToString();
}
private void BooleanValue_OnChanged()
{
VisibilityEnumTest = BooleanValue ? Visibility.Visible : Visibility.Collapsed;
}
[Command]
[RelayCommand]
private void SaveViewModel()
{
// var contents = _serializer.Serialize(Values);

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</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.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Markup;

View File

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

View File

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

View File

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

View File

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