mirror of
https://github.com/holgerb83/ModernWpfPlayground.git
synced 2025-04-19 23:03:49 +02:00
nice features
This commit is contained in:
parent
2467cad2a1
commit
b910d3a1e6
@ -1,6 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.IO;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Windows;
|
||||||
|
using Microsoft.Win32;
|
||||||
using ModernWpfPlayground.Annotations;
|
using ModernWpfPlayground.Annotations;
|
||||||
|
|
||||||
namespace ModernWpfPlayground
|
namespace ModernWpfPlayground
|
||||||
@ -32,5 +36,26 @@ namespace ModernWpfPlayground
|
|||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,15 +3,19 @@
|
|||||||
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:ui="http://schemas.modernwpf.com/2019"
|
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||||
Title="Save your work?"
|
x:Name="LayoutRoot"
|
||||||
|
Title="Delete your work?"
|
||||||
CloseButtonText="Cancel"
|
CloseButtonText="Cancel"
|
||||||
DefaultButton="Close"
|
DefaultButton="Close"
|
||||||
IsShadowEnabled="True"
|
IsShadowEnabled="True"
|
||||||
PrimaryButtonText="Yes"
|
PrimaryButtonText="Yes"
|
||||||
SecondaryButtonText="No">
|
SecondaryButtonText="No">
|
||||||
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
<ui:SimpleStackPanel
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
Spacing="10">
|
||||||
<!-- Content body -->
|
<!-- Content body -->
|
||||||
<TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" />
|
<TextBlock Text="Delete message?" />
|
||||||
<CheckBox Content="Upload your content to the cloud." />
|
<TextBlock TextWrapping="Wrap"><Run Text=""" /><Run Text="{Binding Message, ElementName=LayoutRoot}" /><Run Text=""" /></TextBlock>
|
||||||
</StackPanel>
|
</ui:SimpleStackPanel>
|
||||||
</ui:ContentDialog>
|
</ui:ContentDialog>
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
using ModernWpf.Controls;
|
using System.Windows;
|
||||||
|
|
||||||
namespace ModernWpfPlayground
|
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()
|
public ContentDialogExample()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
<MenuItem Header="New" />
|
<MenuItem Header="New" />
|
||||||
<MenuItem Header="Open" />
|
<MenuItem Header="Open" />
|
||||||
<Separator />
|
<Separator />
|
||||||
<MenuItem Header="Close" />
|
<MenuItem Command="{Binding CloseCommand}" Header="Close" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Edit">
|
<MenuItem Header="Edit">
|
||||||
<MenuItem Header="Copy" />
|
<MenuItem Header="Copy" />
|
||||||
@ -119,7 +119,6 @@
|
|||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="40" />
|
<ColumnDefinition Width="40" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="4" />
|
|
||||||
<ColumnDefinition />
|
<ColumnDefinition />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Border
|
<Border
|
||||||
@ -160,11 +159,7 @@
|
|||||||
<TreeViewItem Header="Child3" />
|
<TreeViewItem Header="Child3" />
|
||||||
</TreeViewItem>
|
</TreeViewItem>
|
||||||
</TreeView>
|
</TreeView>
|
||||||
<GridSplitter
|
<TabControl Grid.Column="2">
|
||||||
Grid.Column="2"
|
|
||||||
Width="4"
|
|
||||||
Background="Transparent" />
|
|
||||||
<TabControl Grid.Column="3">
|
|
||||||
<TabItem Header="Bolt">
|
<TabItem Header="Bolt">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
@ -190,13 +185,12 @@
|
|||||||
Command="{Binding ShowDialogCommand}"
|
Command="{Binding ShowDialogCommand}"
|
||||||
Label="Hello"
|
Label="Hello"
|
||||||
Symbol="x³"
|
Symbol="x³"
|
||||||
Value="World" />
|
Value="{Binding WelcomeMessage}" />
|
||||||
<controls:PropertyPresenter2
|
<controls:PropertyPresenter2
|
||||||
Label="Hallo"
|
Label="Hallo"
|
||||||
Symbol="x²"
|
Symbol="x²"
|
||||||
Value="{Binding ValidationTest}" />
|
Value="{Binding ValidationTest}" />
|
||||||
<controls:PropertyPresenter2 Label="Hello" Value="{Binding BooleanValue}" />
|
<controls:PropertyPresenter2 Label="Hello" Value="{Binding BooleanValue}" />
|
||||||
|
|
||||||
<controls:PropertyPresenter2 Label="Hello">
|
<controls:PropertyPresenter2 Label="Hello">
|
||||||
<Slider
|
<Slider
|
||||||
AutoToolTipPlacement="TopLeft"
|
AutoToolTipPlacement="TopLeft"
|
||||||
|
@ -25,10 +25,7 @@ namespace ModernWpfPlayground
|
|||||||
remove => CommandManager.RequerySuggested -= value;
|
remove => CommandManager.RequerySuggested -= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanExecute(object parameter)
|
public bool CanExecute(object parameter) => _canExecute?.Invoke(parameter) ?? true;
|
||||||
{
|
|
||||||
return _canExecute?.Invoke(parameter) ?? true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Execute(object parameter)
|
public void Execute(object parameter)
|
||||||
{
|
{
|
||||||
|
@ -8,13 +8,15 @@ namespace ModernWpfPlayground
|
|||||||
{
|
{
|
||||||
public WindowViewModel()
|
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();
|
var dialog = new ContentDialogExample {Message = WelcomeMessage};
|
||||||
await dialog.ShowAsync();
|
var result = await dialog.ShowAsync();
|
||||||
|
WelcomeMessage = result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool BooleanValue
|
public bool BooleanValue
|
||||||
@ -41,6 +43,14 @@ namespace ModernWpfPlayground
|
|||||||
set => SetProperty(value);
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user