diff --git a/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs b/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs index 156ca4552bd0f4f048135cc5b886ae35e36a17e6..8857067710a76694bdc98b0584885eaad55cbd8f 100644 --- a/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs +++ b/VECTO3GUI2020/Helper/Converter/NullToVisibilityConverter.cs @@ -7,13 +7,28 @@ namespace VECTO3GUI2020.Helper.Converter { class NullToVisibilityConverter : IValueConverter { + /// <summary> + /// + /// </summary> + /// <param name="value"></param> + /// <param name="targetType"></param> + /// <param name="parameter">set to "invert" to invert the result</param> + /// <param name="culture"></param> + /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if(value == null) + { + bool invert = parameter as string == "invert"; + if (value == null) { + if (invert) { + return Visibility.Visible; + } return Visibility.Collapsed; } else { + if (invert) { + return Visibility.Collapsed; + } return Visibility.Visible; } } diff --git a/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs b/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs index 227bebb57dda2ef521ab6b2a8098cf105aab3bec..876ef38084047d02775fd175a3c4f5df826c610d 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; +using System.Windows; +using VECTO3GUI2020.Helper; using VECTO3GUI2020.ViewModel.Interfaces.Common; namespace VECTO3GUI2020.ViewModel.Implementation.Common @@ -40,5 +42,21 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common } public virtual string Title { get; set; } = "No Title Set"; + + protected void CloseWindow(Window window, IDialogHelper dialogHelper, bool showDialog = true) + { + MessageBoxResult result; + if (showDialog) { + result = dialogHelper.ShowMessageBox("Do you really want to close?", "Close", MessageBoxButton.YesNo, + MessageBoxImage.Question); + } else { + result = MessageBoxResult.Yes; + } + + + if (result == MessageBoxResult.Yes) { + window?.Close(); + } + } } } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs index ab0664fc21781a49a38721b5952a9d4014ce4f34..c24da66929e18e8cdef9752fab1ee663caf01adc 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs @@ -58,6 +58,19 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation #region Commands + + + + private ICommand _closeWindowCommand; + public ICommand CloseWindowCommand + { + get + { + return _closeWindowCommand ?? new RelayCommand<Window>(window => CloseWindow(window, _dialogHelper.Value), window => true); + } + } + + private ICommand _saveVifCommand; public ICommand SaveVIFCommand @@ -296,7 +309,6 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set => _inputComplete = value; } - #endregion } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs index bb569a84ed6cdcb38508b80cf9724e5d2ad0a662..33ff82615d8b0ab71de08ad4dde538597463f8ee 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/NewMultiStageJobViewModel.cs @@ -86,7 +86,16 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation VifPath = fileName; } - + + private ICommand _closeWindow; + + public ICommand CloseWindow + { + get => _closeWindow ?? new RelayCommand<Window>(window => base.CloseWindow(window, _dialogHelper, false), + (window) => MultiStageJobViewModel == null); + } + + #endregion diff --git a/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml b/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml index 6fe9f0f1052724ca97e7b6fed5ee4b985b8fc93a..449554b41c18f989dc1709a95bfe4b9e3eedfd0e 100644 --- a/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml +++ b/VECTO3GUI2020/Views/Multistage/MultiStageView.xaml @@ -16,6 +16,13 @@ Text="{Binding VehicleInputDataFilePath, TargetNullValue=Select Vehicle Input Data . . .}"></customControls:FilePicker> <Border BorderThickness="1" BorderBrush="{DynamicResource ButtonHighlightColor}" Height="40" DockPanel.Dock="Bottom"> <DockPanel LastChildFill="False"> + <Button DockPanel.Dock="Right" + Width="100" + Command="{Binding CloseWindowCommand}" + CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" + Style="{DynamicResource MultiStageButtonStyle1}" + Margin="4" + Padding="4">Close</Button> <Button DockPanel.Dock="Right" Width="100" Command="{Binding SaveVIFCommand}" @@ -29,7 +36,13 @@ Margin="4" Padding="4" Command="{Binding SaveInputDataCommand}">Save Input</Button> - <Button DockPanel.Dock="Right" Width="100" Style="{DynamicResource MultiStageButtonStyle1}" Margin="4" Padding="4" Command="{Binding SaveInputDataAsCommand}">Save Input As ... </Button> + <Button + DockPanel.Dock="Right" + Width="100" + Style="{DynamicResource MultiStageButtonStyle1}" + Margin="4" + Padding="4" + Command="{Binding SaveInputDataAsCommand}">Save Input As ... </Button> </DockPanel> </Border> <ContentControl DockPanel.Dock="Top" Content="{Binding ManufacturingStageViewModel}"/> diff --git a/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml b/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml index 6a6f7ee479b7cd40db1d1e7445d6a228ebb6e86c..03e223fc519d0201a90adfb8a754447dd5b4b106 100644 --- a/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml +++ b/VECTO3GUI2020/Views/Multistage/NewMultistageFileView.xaml @@ -14,7 +14,15 @@ <Grid DockPanel.Dock="Top"> <customControls:FilePicker x:Name="NewMultistageFilePicker" Grid.Row="0" Text="{Binding VifPath}" HorizontalAlignment="Stretch" Command="{Binding AddVifFile}"/> </Grid> + <Button Style="{DynamicResource MultiStageButtonStyle1}" + Margin="4" DockPanel.Dock="Bottom" + Visibility="{Binding MultiStageJobViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=invert}" + Command="{Binding CloseWindow}" + CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"> + Cancel + </Button> <ContentControl Grid.Row="2" Content="{Binding MultiStageJobViewModel}"/> + </DockPanel> </Grid> </Grid>