This commit is contained in:
Holger Börchers 2021-10-27 22:56:36 +02:00
parent 48d244ea20
commit ae6192bd1f
16 changed files with 50 additions and 74 deletions

3
.gitignore vendored
View File

@ -337,4 +337,5 @@ ASALocalRun/
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb
.ionide

2
.vscode/launch.json vendored
View File

@ -10,7 +10,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/App/bin/Debug/net5.0-windows10.0.18362.0/win-x64/ModernWpfPlayground.dll",
"program": "${workspaceFolder}/App/bin/Debug/net5.0-windows/win-x64/ModernWpfPlayground.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console

View File

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

View File

@ -1,5 +1,3 @@
using System.Windows;
[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
@ -7,4 +5,4 @@ using System.Windows;
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)
)]
)]

View File

@ -1,6 +1,4 @@
using System.Windows;
namespace ModernWpfPlayground
namespace ModernWpfPlayground
{
public partial class ContentDialogExample
{

3
App/GlobalUsings.cs Normal file
View File

@ -0,0 +1,3 @@
global using System;
global using MvvmGen;
global using System.Windows;

View File

@ -22,22 +22,10 @@
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Window.Resources>
<local:PixelsToGridLengthConverter x:Key="PixelsToGridLength" />
</Window.Resources>
<Window.InputBindings>
<KeyBinding
Key="O"
Command="{Binding OpenViewModelCommand}"
Modifiers="Control" />
<KeyBinding
Key="S"
Command="{Binding SaveViewModelCommand}"
Modifiers="Control" />
<KeyBinding
Key="N"
Command="{Binding ResetViewModelCommand}"
Modifiers="Control" />
<KeyBinding Key="O" Modifiers="Control" />
<KeyBinding Key="S" Modifiers="Control" />
<KeyBinding Key="N" Modifiers="Control" />
</Window.InputBindings>
<DockPanel>
@ -58,7 +46,7 @@
</Grid.Style>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayLeftInset), Converter={StaticResource PixelsToGridLength}}" />
<ColumnDefinition Width="{Binding ElementName=Window, Path=(ui:TitleBar.SystemOverlayLeftInset), Converter={local:PixelsToGridLengthConverter}}" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
@ -220,7 +208,7 @@
</ui:SplitView.Pane>
<!-- Content -->
<TabControl>
<TabItem ui:ControlHelper.CornerRadius="0" Header="Bolt">
<TabItem Header="Bolt">
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True">
<Grid>
<Grid.ColumnDefinitions>
@ -246,12 +234,15 @@
</ScrollViewer>
</TabItem>
<TabItem
ui:ControlHelper.CornerRadius="0"
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
@ -264,10 +255,9 @@
Label="Hallo"
Symbol="x²"
Value="{Binding ValidationTest, UpdateSourceTrigger=PropertyChanged}" />
<controls:PropertyPresenter
Label="Good bye"
Symbol="x²"
Value="{Binding ValidationTest, UpdateSourceTrigger=PropertyChanged}" />
<controls:PropertyPresenter Label="Good bye" Symbol="x²">
<ui:NumberBox SpinButtonPlacementMode="Compact" Value="{Binding ValidationTest, UpdateSourceTrigger=PropertyChanged}" />
</controls:PropertyPresenter>
<Grid Margin="0,5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />

View File

@ -1,6 +1,4 @@
using ModernWpfPlayground.Types;
using MvvmGen;
using System.Windows;
using static ModernWpf.ThemeManager;
namespace ModernWpfPlayground
@ -59,7 +57,7 @@ namespace ModernWpfPlayground
[Command]
private async void ShowDialog()
{
var dialog = new ContentDialogExample {Message = WelcomeMessage};
var dialog = new ContentDialogExample { Message = WelcomeMessage };
var result = await dialog.ShowAsync();
WelcomeMessage = result.ToString();
}
@ -83,6 +81,5 @@ namespace ModernWpfPlayground
//
// File.WriteAllText(Path, contents);
}
}
}

View File

@ -2,27 +2,31 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.18362.0</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
<PackageReference Include="ModernWpfUis" Version="1.2.0" />
<PackageReference Include="MvvmGen" Version="1.1.1" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.8.0" />
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.11.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Controls\Controls.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="MvvmStuff" />
</ItemGroup>
</Project>

View File

@ -1,20 +0,0 @@
using System;
using System.Globalization;
namespace ModernWpfPlayground.MvvmStuff
{
public static class DeserializationExtension
{
public static object? Convert(object? value, Type propertyType)
{
if (value is null) return Activator.CreateInstance(propertyType);
if (propertyType.IsEnum && value is string s)
{
return Enum.Parse(propertyType, s);
}
return System.Convert.ChangeType(value, propertyType, CultureInfo.InvariantCulture);
}
}
}

View File

@ -1,12 +1,13 @@
using System;
using System.Globalization;
using System.Windows;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace ModernWpfPlayground
{
public class PixelsToGridLengthConverter : IValueConverter
public class PixelsToGridLengthConverter : MarkupExtension, IValueConverter
{
private static PixelsToGridLengthConverter? _converter;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is double d ? new GridLength(d) : new GridLength(1.0, GridUnitType.Auto);
@ -16,5 +17,8 @@ namespace ModernWpfPlayground
{
throw new NotImplementedException();
}
public override object ProvideValue(IServiceProvider serviceProvider) =>
_converter ??= new PixelsToGridLengthConverter();
}
}

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,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -4,17 +4,20 @@ using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Markup;
namespace Controls
{
/// <summary>
/// Converts enums to a List with KeyValuePairs.
/// </summary>
public class EnumToKeyValueListConverter : IValueConverter
public class EnumToItemSourceConverter : MarkupExtension, IValueConverter
{
private static EnumToItemSourceConverter? _converter;
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is Enum)) return Binding.DoNothing;
if (value is not Enum) return Binding.DoNothing;
return (from object enumValue in Enum.GetValues(value.GetType())
select new KeyValuePair<string, object>(GetDescription(enumValue), enumValue)).ToList();
}
@ -40,5 +43,7 @@ namespace Controls
{
return Binding.DoNothing;
}
public override object ProvideValue(IServiceProvider serviceProvider) => _converter ??= new EnumToItemSourceConverter();
}
}

View File

@ -86,12 +86,11 @@
</CheckBox.Style>
</CheckBox>
</DataTemplate>
<controls:EnumToKeyValueListConverter x:Key="EnumToKeyValuePairConverter" />
<DataTemplate x:Key="EnumComboBoxDataTemplate">
<ComboBox
HorizontalAlignment="Stretch"
DisplayMemberPath="Key"
ItemsSource="{Binding Value, ElementName=LayoutRoot, Converter={StaticResource EnumToKeyValuePairConverter}}"
ItemsSource="{Binding Value, ElementName=LayoutRoot, Converter={controls:EnumToItemSourceConverter}}"
SelectedValue="{Binding Value, ElementName=LayoutRoot}"
SelectedValuePath="Value"
Validation.ErrorTemplate="{DynamicResource ValidationErrorTemplate}"