From 5e327974560b4e1a873c1095885194b3b8cd9eae Mon Sep 17 00:00:00 2001 From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at> Date: Tue, 22 Jun 2021 10:41:49 +0200 Subject: [PATCH] Adding VIF to joblist after saving --- .../Behaviours/HideOnMainWindowBehavior.cs | 32 ++++++++++ VECTO3GUI2020/Behaviours/MinSizeBehavior.cs | 63 +++++++++++++++++++ VECTO3GUI2020/DataGridStyles.xaml | 5 +- VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs | 2 +- VECTO3GUI2020/VECTO3GUI2020.csproj | 2 + .../MultistageJobViewModel_v0_1.cs | 10 ++- VECTO3GUI2020/Views/JoblistView.xaml.cs | 7 ++- VECTO3GUI2020/Views/SettingsView.xaml | 8 ++- 8 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 VECTO3GUI2020/Behaviours/HideOnMainWindowBehavior.cs create mode 100644 VECTO3GUI2020/Behaviours/MinSizeBehavior.cs diff --git a/VECTO3GUI2020/Behaviours/HideOnMainWindowBehavior.cs b/VECTO3GUI2020/Behaviours/HideOnMainWindowBehavior.cs new file mode 100644 index 0000000000..5ecc5f7514 --- /dev/null +++ b/VECTO3GUI2020/Behaviours/HideOnMainWindowBehavior.cs @@ -0,0 +1,32 @@ +using System.Windows; +using Microsoft.Xaml.Behaviors; + +namespace VECTO3GUI2020.Behaviours +{ + public class HideOnMainWindowBehavior : Behavior<FrameworkElement> + { + #region Overrides of Behavior + + private Visibility savedState; + protected override void OnAttached() + { + + base.OnAttached(); + var window = Window.GetWindow(this.AssociatedObject); + if (window == Application.Current.MainWindow) { + savedState = AssociatedObject.Visibility; + this.AssociatedObject.Visibility = Visibility.Hidden; + } + } + + protected override void OnDetaching() + { + if (savedState != null) { + this.AssociatedObject.Visibility = savedState; + } + base.OnDetaching(); + } + + #endregion + } +} \ No newline at end of file diff --git a/VECTO3GUI2020/Behaviours/MinSizeBehavior.cs b/VECTO3GUI2020/Behaviours/MinSizeBehavior.cs new file mode 100644 index 0000000000..1a2bb8675f --- /dev/null +++ b/VECTO3GUI2020/Behaviours/MinSizeBehavior.cs @@ -0,0 +1,63 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using Microsoft.Xaml.Behaviors; + +namespace VECTO3GUI2020.Behaviours +{ + public class MinSizeBehavior : Behavior<Window> + { + #region Overrides of Behavior + + private double _initialMinWidth; + private double _initialMinHeight; + + protected override void OnAttached() + { + this.AssociatedObject.Activated += OnWindowActivated; + _initialMinHeight = this.AssociatedObject.MinHeight; + _initialMinWidth = this.AssociatedObject.MinWidth; + base.OnAttached(); + + } + + private void OnWindowActivated(object sender, EventArgs e) + { + for(var i = 0; i < VisualTreeHelper.GetChildrenCount((Window)sender); i++) + { + var child = VisualTreeHelper.GetChild((Window)sender, 0) as FrameworkElement; + if (child.MinHeight != 0 && this.AssociatedObject.MinHeight == 0) { + this.AssociatedObject.MinHeight = child.MinHeight; + } + if (child.MinWidth != 0 && this.AssociatedObject.MinWidth == 0) + { + this.AssociatedObject.MinWidth = child.MinWidth; + } + } + + + + } + + private void OnWindowInitialized(object sender, EventArgs e) + { + + + + + } + + protected override void OnDetaching() + { + + + this.AssociatedObject.Initialized -= OnWindowActivated; + + base.OnDetaching(); + + } + + #endregion + } +} \ No newline at end of file diff --git a/VECTO3GUI2020/DataGridStyles.xaml b/VECTO3GUI2020/DataGridStyles.xaml index 8eca24461f..3d2178c42d 100644 --- a/VECTO3GUI2020/DataGridStyles.xaml +++ b/VECTO3GUI2020/DataGridStyles.xaml @@ -38,11 +38,14 @@ <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="BorderThickness" Value="0"/> + <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridCell}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"> - <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> + <ContentPresenter VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"> + + </ContentPresenter> </Border> </ControlTemplate> </Setter.Value> diff --git a/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs b/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs index 5dd4bcd596..e2c1ddb92f 100644 --- a/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs +++ b/VECTO3GUI2020/Ninject/Vecto3GUI2020Module.cs @@ -15,7 +15,7 @@ namespace VECTO3GUI2020.Ninject public override void Load() { - Bind<IJobListViewModel>().To<JobListViewModel>(); + Bind<IJobListViewModel>().To<JobListViewModel>().InSingletonScope(); Bind<IMainWindowViewModel>().To<MainWindowViewModel>(); Bind<IMainViewModel>().To<JobListViewModel>(); Bind<ISettingsViewModel>().To<SettingsViewModel>(); diff --git a/VECTO3GUI2020/VECTO3GUI2020.csproj b/VECTO3GUI2020/VECTO3GUI2020.csproj index 80fb39c755..b0f12108be 100644 --- a/VECTO3GUI2020/VECTO3GUI2020.csproj +++ b/VECTO3GUI2020/VECTO3GUI2020.csproj @@ -155,6 +155,8 @@ <SubType>Designer</SubType> </ApplicationDefinition> <Compile Include="Behaviours\AutoScrollDataGridBehaviour.cs" /> + <Compile Include="Behaviours\HideOnMainWindowBehavior.cs" /> + <Compile Include="Behaviours\MinSizeBehavior.cs" /> <Compile Include="Helper\ConvertedSIDummyCreator.cs" /> <Compile Include="Helper\Converter\AlwaysVisibleConverter.cs" /> <Compile Include="Helper\Converter\BoolToVisibilityConverter.cs" /> diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs index e7fc911c90..bc70a46ddb 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs @@ -63,11 +63,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation set => SetProperty(ref _manufacturingStageViewModel, value); } - public MultiStageJobViewModel_v0_1(IMultistageBusInputDataProvider inputData, IMultiStageViewModelFactory vmFactory, IMultistageDependencies multistageDependencies, IXMLInputDataReader inputDataReader) + public MultiStageJobViewModel_v0_1(IMultistageBusInputDataProvider inputData, IMultiStageViewModelFactory vmFactory, IMultistageDependencies multistageDependencies, IXMLInputDataReader inputDataReader, IJobListViewModel jobListViewModel) { Title = "Edit Multistage Job"; _dataSource = inputData.DataSource; _jobInputData = inputData.JobInputData; + _jobListViewModel = jobListViewModel; _inputData = inputData; _vmFactory = vmFactory; _consolidateManufacturingStage = _jobInputData.ConsolidateManufacturingStage; @@ -154,12 +155,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation SaveVif(vifData:this, outputFile:outputFile, dialogHelper:_dialogHelper.Value); } - public static void SaveVif(IMultistageVIFInputData vifData, FileOutputVIFWriter writer, IDialogHelper dialogHelper = null) + public void SaveVif(IMultistageVIFInputData vifData, FileOutputVIFWriter writer, IDialogHelper dialogHelper = null) { SaveVif(vifData, null, writer, dialogHelper); } - public static void SaveVif(IMultistageVIFInputData vifData, string outputFile, + private void SaveVif(IMultistageVIFInputData vifData, string outputFile, FileOutputVIFWriter writer = null, IDialogHelper dialogHelper = null) { try { @@ -197,7 +198,9 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation } else { dialogHelper?.ShowMessageBox($"Written to {writer.XMLMultistageReportFileName}", "Info", MessageBoxButton.OK, MessageBoxImage.Information); + _jobListViewModel.AddJobAsync(writer.XMLMultistageReportFileName); Debug.WriteLine($"Written to {writer.XMLMultistageReportFileName}"); + } } @@ -308,6 +311,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation private readonly IMultistageBusInputDataProvider _inputData; private bool _selected; private readonly bool _exempted; + private readonly IJobListViewModel _jobListViewModel; public ICommand LoadVehicleDataCommand { diff --git a/VECTO3GUI2020/Views/JoblistView.xaml.cs b/VECTO3GUI2020/Views/JoblistView.xaml.cs index 7a2f519898..7c73729a88 100644 --- a/VECTO3GUI2020/Views/JoblistView.xaml.cs +++ b/VECTO3GUI2020/Views/JoblistView.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Threading.Tasks; +using System.Windows; using System.Windows.Controls; using System.Windows.Input; using VECTO3GUI2020.ViewModel.Implementation; @@ -19,7 +20,7 @@ namespace VECTO3GUI2020.Views } - private void JobDataGrid_OnDrop(object sender, DragEventArgs e) + private async void JobDataGrid_OnDrop(object sender, DragEventArgs e) { var success = true; if (e.Data.GetDataPresent(DataFormats.FileDrop)) { @@ -28,7 +29,7 @@ namespace VECTO3GUI2020.Views var fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[]; if (fileNames != null) { foreach (var fileName in fileNames) { - ((JobListViewModel)this.DataContext).AddJobAsync(fileName); + await ((JobListViewModel)this.DataContext).AddJobAsync(fileName); } } diff --git a/VECTO3GUI2020/Views/SettingsView.xaml b/VECTO3GUI2020/Views/SettingsView.xaml index 29240bb0d6..b4ce56aa8c 100644 --- a/VECTO3GUI2020/Views/SettingsView.xaml +++ b/VECTO3GUI2020/Views/SettingsView.xaml @@ -6,7 +6,10 @@ xmlns:local="clr-namespace:VECTO3GUI2020.Views" xmlns:customControls="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" xmlns:implementation="clr-namespace:VECTO3GUI2020.ViewModel.Implementation" - mc:Ignorable="d" d:DataContext="{d:DesignInstance implementation:SettingsViewModel }"> + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" + xmlns:behaviour="clr-namespace:VECTO3GUI2020.Behaviours" + mc:Ignorable="d" d:DataContext="{d:DesignInstance implementation:SettingsViewModel }" + MinHeight="200" MinWidth="400"> <UserControl.Resources> <Style TargetType="Label"> <Setter Property="Margin" Value="4 4 4 4"></Setter> @@ -96,6 +99,9 @@ <!--</Grid>--> <DockPanel DockPanel.Dock="Bottom" LastChildFill="False"> + <i:Interaction.Behaviors> + <behaviour:HideOnMainWindowBehavior></behaviour:HideOnMainWindowBehavior> + </i:Interaction.Behaviors> <Button DockPanel.Dock="Right" Width="100" Command="{Binding CloseWindowCommand}" -- GitLab