Fun with MaterialDesignInXAML

This commit is contained in:
Holger Boerchers 2018-08-03 21:57:38 +02:00
parent d39ffa2cb2
commit a08d551403
3 changed files with 125 additions and 39 deletions

View File

@ -5,8 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:Example" xmlns:local="clr-namespace:Example"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
Title="MainWindow" Title="MainWindow"
Width="800" Width="800"
@ -26,8 +26,52 @@
<i:InvokeCommandAction Command="{Binding UpdateCommand}" CommandParameter="True" /> <i:InvokeCommandAction Command="{Binding UpdateCommand}" CommandParameter="True" />
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
<md:DialogHost IsOpen="{Binding ShowRestartAppDialog}">
<md:DialogHost.DialogContent>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Text="The update was installed successful. Do you want to restart?" />
<Button
Grid.Row="1"
Grid.Column="0"
Command="{Binding RestartAppDialogCommand}"
IsCancel="False"
Style="{StaticResource MaterialDesignFlatButton}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
True
</system:Boolean>
</Button.CommandParameter>
YES
</Button>
<Button
Grid.Row="1"
Grid.Column="1"
Command="{Binding RestartAppDialogCommand}"
IsCancel="True"
Style="{StaticResource MaterialDesignFlatButton}">
<Button.CommandParameter>
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
False
</system:Boolean>
</Button.CommandParameter>
NO
</Button>
</Grid>
</md:DialogHost.DialogContent>
<DockPanel> <DockPanel>
<materialDesign:Snackbar <md:Snackbar
Margin="10,0" Margin="10,0"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
DockPanel.Dock="Bottom" DockPanel.Dock="Bottom"
@ -57,4 +101,5 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</DockPanel> </DockPanel>
</md:DialogHost>
</Window> </Window>

View File

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Katteker;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using Prism.Commands; using Prism.Commands;
using Prism.Mvvm; using Prism.Mvvm;
@ -11,20 +12,41 @@ namespace Example
[JetBrains.Annotations.UsedImplicitly] [JetBrains.Annotations.UsedImplicitly]
public class MainWindowViewModel : BindableBase, IDisposable public class MainWindowViewModel : BindableBase, IDisposable
{ {
private bool _showRestartAppDialog;
private UpdateManager _updateManager;
public MainWindowViewModel() public MainWindowViewModel()
{ {
_updateManager = UpdateManager.Create();
UpdateCommand = new DelegateCommand<string>(async x => await UpdateAsync(x).ConfigureAwait(false)); UpdateCommand = new DelegateCommand<string>(async x => await UpdateAsync(x).ConfigureAwait(false));
RestartAppDialogCommand = new DelegateCommand<object>(RestartApp);
} }
private void RestartApp(object obj)
{
if (obj is bool restart && restart)
{
_updateManager.RestartApp();
}
ShowRestartAppDialog = false;
}
private async Task UpdateAsync(string startup) private async Task UpdateAsync(string startup)
{ {
var silent = !bool.Parse(startup); var silent = bool.Parse(startup);
try try
{ {
var manager = Katteker.UpdateManager.Create(); var releases = (await _updateManager.CheckForUpdateAsync()).ToList();
var releases = await manager.CheckForUpdateAsync(); if (releases.Any())
MessageQueue.Enqueue(releases.Any() ? "Update available" : "No Update available.", true); {
MessageQueue.Enqueue("Update available", "Update now", ActionHandler);
}
else if (!silent)
{
MessageQueue.Enqueue("No Update available.", true);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -35,10 +57,27 @@ namespace Example
} }
} }
private async void ActionHandler()
{
if (await _updateManager.UpdateAppAsync().ConfigureAwait(false))
{
ShowRestartAppDialog = true;
//manager.RestartApp();
}
}
public ICommand UpdateCommand { get; } public ICommand UpdateCommand { get; }
public SnackbarMessageQueue MessageQueue { get; } = new SnackbarMessageQueue(); public SnackbarMessageQueue MessageQueue { get; } = new SnackbarMessageQueue();
public bool ShowRestartAppDialog
{
get => _showRestartAppDialog;
set => SetProperty(ref _showRestartAppDialog, value);
}
public ICommand RestartAppDialogCommand { get; }
public void Dispose() public void Dispose()
{ {
MessageQueue?.Dispose(); MessageQueue?.Dispose();

View File

@ -49,5 +49,7 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0")] [assembly: AssemblyVersion("1.2.3")]
[assembly: AssemblyFileVersion("1.2.0")] [assembly: AssemblyFileVersion("1.2.3")]
[assembly: Guid("549EEC1D-D014-41C1-9442-F449911B1B50")]