Fun with MaterialDesignInXAML
This commit is contained in:
parent
d39ffa2cb2
commit
a08d551403
@ -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,35 +26,80 @@
|
|||||||
<i:InvokeCommandAction Command="{Binding UpdateCommand}" CommandParameter="True" />
|
<i:InvokeCommandAction Command="{Binding UpdateCommand}" CommandParameter="True" />
|
||||||
</i:EventTrigger>
|
</i:EventTrigger>
|
||||||
</i:Interaction.Triggers>
|
</i:Interaction.Triggers>
|
||||||
<DockPanel>
|
<md:DialogHost IsOpen="{Binding ShowRestartAppDialog}">
|
||||||
<materialDesign:Snackbar
|
<md:DialogHost.DialogContent>
|
||||||
Margin="10,0"
|
<Grid Margin="10">
|
||||||
HorizontalAlignment="Stretch"
|
<Grid.ColumnDefinitions>
|
||||||
DockPanel.Dock="Bottom"
|
<ColumnDefinition />
|
||||||
MessageQueue="{Binding MessageQueue}" />
|
<ColumnDefinition />
|
||||||
<StackPanel>
|
</Grid.ColumnDefinitions>
|
||||||
<Button
|
<Grid.RowDefinitions>
|
||||||
Height="45"
|
<RowDefinition />
|
||||||
Margin="10"
|
<RowDefinition />
|
||||||
Command="{Binding UpdateCommand}"
|
</Grid.RowDefinitions>
|
||||||
CommandParameter="False"
|
<TextBlock
|
||||||
Content="Update"
|
Grid.Row="0"
|
||||||
FontSize="24" />
|
Grid.Column="0"
|
||||||
<TextBlock
|
Grid.ColumnSpan="2"
|
||||||
Margin="20"
|
Text="The update was installed successful. Do you want to restart?" />
|
||||||
HorizontalAlignment="Center"
|
<Button
|
||||||
FontSize="60"
|
Grid.Row="1"
|
||||||
RenderTransformOrigin="0.5,0.5"
|
Grid.Column="0"
|
||||||
Text=":-)">
|
Command="{Binding RestartAppDialogCommand}"
|
||||||
<TextBlock.RenderTransform>
|
IsCancel="False"
|
||||||
<TransformGroup>
|
Style="{StaticResource MaterialDesignFlatButton}">
|
||||||
<ScaleTransform />
|
<Button.CommandParameter>
|
||||||
<SkewTransform />
|
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||||
<RotateTransform Angle="90" />
|
True
|
||||||
<TranslateTransform />
|
</system:Boolean>
|
||||||
</TransformGroup>
|
</Button.CommandParameter>
|
||||||
</TextBlock.RenderTransform>
|
YES
|
||||||
</TextBlock>
|
</Button>
|
||||||
</StackPanel>
|
<Button
|
||||||
</DockPanel>
|
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>
|
</Window>
|
@ -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();
|
||||||
|
@ -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")]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user