nice features

This commit is contained in:
Holger Börchers 2020-02-18 20:08:06 +01:00
parent 2467cad2a1
commit b910d3a1e6
6 changed files with 64 additions and 25 deletions

View File

@ -1,6 +1,10 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Windows;
using Microsoft.Win32;
using ModernWpfPlayground.Annotations;
namespace ModernWpfPlayground
@ -32,5 +36,26 @@ namespace ModernWpfPlayground
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void SaveViewModel()
{
var contents = JsonSerializer.Serialize(_valueDict);
var saveFileDialog = new SaveFileDialog();
var result = saveFileDialog.ShowDialog(Application.Current.MainWindow?.Owner);
if (result == true)
{
File.WriteAllText(saveFileDialog.FileName, contents);
}
}
public void LoadViewModel(string path)
{
var contents = File.ReadAllText(path);
var obj = JsonSerializer.Deserialize<Dictionary<string, object>>(contents);
foreach (var (key, value) in obj)
{
_valueDict[key] = value;
OnPropertyChanged(key);
}
}
}
}

View File

@ -3,15 +3,19 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="http://schemas.modernwpf.com/2019"
Title="Save your work?"
x:Name="LayoutRoot"
Title="Delete your work?"
CloseButtonText="Cancel"
DefaultButton="Close"
IsShadowEnabled="True"
PrimaryButtonText="Yes"
SecondaryButtonText="No">
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ui:SimpleStackPanel
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Spacing="10">
<!-- Content body -->
<TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" />
<CheckBox Content="Upload your content to the cloud." />
</StackPanel>
<TextBlock Text="Delete message?" />
<TextBlock TextWrapping="Wrap"><Run Text="&quot;" /><Run Text="{Binding Message, ElementName=LayoutRoot}" /><Run Text="&quot;" /></TextBlock>
</ui:SimpleStackPanel>
</ui:ContentDialog>

View File

@ -1,9 +1,18 @@
using ModernWpf.Controls;
using System.Windows;
namespace ModernWpfPlayground
{
public partial class ContentDialogExample : ContentDialog
public partial class ContentDialogExample
{
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
"Message", typeof(string), typeof(ContentDialogExample), new PropertyMetadata(default(string)));
public string Message
{
get => (string) GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}
public ContentDialogExample()
{
InitializeComponent();

View File

@ -66,7 +66,7 @@
<MenuItem Header="New" />
<MenuItem Header="Open" />
<Separator />
<MenuItem Header="Close" />
<MenuItem Command="{Binding CloseCommand}" Header="Close" />
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Header="Copy" />
@ -119,7 +119,6 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="4" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
@ -160,11 +159,7 @@
<TreeViewItem Header="Child3" />
</TreeViewItem>
</TreeView>
<GridSplitter
Grid.Column="2"
Width="4"
Background="Transparent" />
<TabControl Grid.Column="3">
<TabControl Grid.Column="2">
<TabItem Header="Bolt">
<Grid>
<Grid.ColumnDefinitions>
@ -190,13 +185,12 @@
Command="{Binding ShowDialogCommand}"
Label="Hello"
Symbol="x³"
Value="World" />
Value="{Binding WelcomeMessage}" />
<controls:PropertyPresenter2
Label="Hallo"
Symbol="x²"
Value="{Binding ValidationTest}" />
<controls:PropertyPresenter2 Label="Hello" Value="{Binding BooleanValue}" />
<controls:PropertyPresenter2 Label="Hello">
<Slider
AutoToolTipPlacement="TopLeft"

View File

@ -25,10 +25,7 @@ namespace ModernWpfPlayground
remove => CommandManager.RequerySuggested -= value;
}
public bool CanExecute(object parameter)
{
return _canExecute?.Invoke(parameter) ?? true;
}
public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true;
public void Execute(object parameter)
{

View File

@ -8,13 +8,15 @@ namespace ModernWpfPlayground
{
public WindowViewModel()
{
ShowDialogCommand = new RelayCommand(async x => await ShowDialogAsync(x));
ShowDialogCommand = new RelayCommand(async x => await ShowDialogAsync());
CloseCommand = new RelayCommand(x => Application.Current.Shutdown());
}
private async Task ShowDialogAsync(object obj)
private async Task ShowDialogAsync()
{
var dialog = new ContentDialogExample();
await dialog.ShowAsync();
var dialog = new ContentDialogExample {Message = WelcomeMessage};
var result = await dialog.ShowAsync();
WelcomeMessage = result.ToString();
}
public bool BooleanValue
@ -41,6 +43,14 @@ namespace ModernWpfPlayground
set => SetProperty(value);
}
public ICommand ShowDialogCommand { get; }
public RelayCommand ShowDialogCommand { get; }
public string WelcomeMessage
{
get => GetProperty("Shadow of the empire");
set => SetProperty(value);
}
public ICommand CloseCommand { get; }
}
}