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:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:Example"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
Title="MainWindow"
Width="800"
@ -26,35 +26,80 @@
<i:InvokeCommandAction Command="{Binding UpdateCommand}" CommandParameter="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<DockPanel>
<materialDesign:Snackbar
Margin="10,0"
HorizontalAlignment="Stretch"
DockPanel.Dock="Bottom"
MessageQueue="{Binding MessageQueue}" />
<StackPanel>
<Button
Height="45"
Margin="10"
Command="{Binding UpdateCommand}"
CommandParameter="False"
Content="Update"
FontSize="24" />
<TextBlock
Margin="20"
HorizontalAlignment="Center"
FontSize="60"
RenderTransformOrigin="0.5,0.5"
Text=":-)">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform Angle="90" />
<TranslateTransform />
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>
</DockPanel>
<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>
<md:Snackbar
Margin="10,0"
HorizontalAlignment="Stretch"
DockPanel.Dock="Bottom"
MessageQueue="{Binding MessageQueue}" />
<StackPanel>
<Button
Height="45"
Margin="10"
Command="{Binding UpdateCommand}"
CommandParameter="False"
Content="Update"
FontSize="24" />
<TextBlock
Margin="20"
HorizontalAlignment="Center"
FontSize="60"
RenderTransformOrigin="0.5,0.5"
Text=":-)">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform Angle="90" />
<TranslateTransform />
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</StackPanel>
</DockPanel>
</md:DialogHost>
</Window>

View File

@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Katteker;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
@ -11,20 +12,41 @@ namespace Example
[JetBrains.Annotations.UsedImplicitly]
public class MainWindowViewModel : BindableBase, IDisposable
{
private bool _showRestartAppDialog;
private UpdateManager _updateManager;
public MainWindowViewModel()
{
_updateManager = UpdateManager.Create();
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)
{
var silent = !bool.Parse(startup);
var silent = bool.Parse(startup);
try
{
var manager = Katteker.UpdateManager.Create();
var releases = await manager.CheckForUpdateAsync();
MessageQueue.Enqueue(releases.Any() ? "Update available" : "No Update available.", true);
var releases = (await _updateManager.CheckForUpdateAsync()).ToList();
if (releases.Any())
{
MessageQueue.Enqueue("Update available", "Update now", ActionHandler);
}
else if (!silent)
{
MessageQueue.Enqueue("No Update available.", true);
}
}
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 SnackbarMessageQueue MessageQueue { get; } = new SnackbarMessageQueue();
public bool ShowRestartAppDialog
{
get => _showRestartAppDialog;
set => SetProperty(ref _showRestartAppDialog, value);
}
public ICommand RestartAppDialogCommand { get; }
public void 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
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.3")]
[assembly: AssemblyFileVersion("1.2.3")]
[assembly: Guid("549EEC1D-D014-41C1-9442-F449911B1B50")]