diff --git a/VECTO3GUI2020/Helper/WindowHelper.cs b/VECTO3GUI2020/Helper/WindowHelper.cs index d864a598699aa4333a711367afd6a5409d81a451..5e5bc2b3004a6b8489dddc0a18c224b0f2bcb321 100644 --- a/VECTO3GUI2020/Helper/WindowHelper.cs +++ b/VECTO3GUI2020/Helper/WindowHelper.cs @@ -1,6 +1,10 @@ -using System.Windows; -using VECTO3GUI2020.ViewModel.Implementation.Common; +using System; +using System.Windows; +using System.Windows.Data; +using System.Windows.Forms; +using VECTO3GUI2020.Properties; using VECTO3GUI2020.ViewModel.Interfaces.Common; +using Binding = System.Windows.Data.Binding; namespace VECTO3GUI2020.Helper { @@ -10,21 +14,47 @@ namespace VECTO3GUI2020.Helper public void ShowWindow(object viewModel) { + IViewModelBase viewModelBase = (IViewModelBase)viewModel; + var height = viewModelBase?.Height ?? Double.NaN; + var width = viewModelBase?.Height ?? Double.NaN; + var sizeToContent = viewModelBase?.SizeToContent ?? SizeToContent.Manual; + var title = viewModelBase?.Title ?? GUILabels.DefaultTitle; + + var window = new Window { Content = viewModel, - Width = 800, - Height = 600, - WindowStartupLocation = WindowStartupLocation.CenterScreen + Height = height, + Width = width, + SizeToContent = sizeToContent, + WindowStartupLocation = WindowStartupLocation.CenterScreen, + Title = title }; - - - if (viewModel is IViewModelBase vmBase) { - window.Title = vmBase.Title; + if (viewModelBase != null) { + SetBinding(viewModelBase, window, new PropertyPath(nameof(viewModelBase.Height)), FrameworkElement.HeightProperty ); + SetBinding(viewModelBase, window, new PropertyPath(nameof(viewModelBase.Width)), FrameworkElement.WidthProperty); + SetBinding(viewModelBase, window, new PropertyPath(nameof(viewModelBase.SizeToContent)), Window.SizeToContentProperty); + SetBinding(viewModelBase, window, new PropertyPath(nameof(viewModelBase.Title)), Window.TitleProperty); } + window.Show(); } - + private static void SetBinding(IViewModelBase viewModelBase, + Window window, + PropertyPath path, + DependencyProperty dependencyProperty, + UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.PropertyChanged, + BindingMode mode = BindingMode.TwoWay + ) + { + Binding binding = new Binding() { + Source = viewModelBase, + Path = path, + UpdateSourceTrigger = updateSourceTrigger, + Mode = mode + }; + BindingOperations.SetBinding(window, dependencyProperty, binding); + } } } diff --git a/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs index 0722eb5f471dd8ba374acaa1eb4188af8f3315c1..feeaa18427ad0423d85cfd0e290604f6bd50e30e 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/Common/AdditionalJobInfoViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.ObjectModel; using System.Linq; +using System.Windows; using TUGraz.VectoCommon.InputData; using VECTO3GUI2020.ViewModel.Interfaces.Common; using VECTO3GUI2020.ViewModel.MultiStage.Implementation; @@ -13,8 +14,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common } public class AdditionalJobInfoViewModelBase : ViewModelBase, IAdditionalJobInfoViewModel { - private IViewModelBase _parent - ; + private IViewModelBase _parent; #region Implementation of IAdditionalJobInfoViewModel @@ -41,6 +41,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common public AdditionalJobInfoViewModelMultiStage() { Title = "Multistage Job Info"; + SizeToContent = SizeToContent.WidthAndHeight; } #region Overrides of AdditionalJobInfoViewModelBase diff --git a/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs b/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs index ed74e17b992a44ed192d18b6f425dbd307f48e77..cd76d97aa208c8c9c4910d069e72e85055497e40 100644 --- a/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/Implementation/Common/ViewModelBase.cs @@ -20,12 +20,36 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common { private string _error; public event PropertyChangedEventHandler PropertyChanged; - /// <summary> - /// Needs to be called when a Property is changed - /// </summary> - /// - /// <param name="name">Is automatically set to CallerMemberName</param> - protected void OnPropertyChanged([CallerMemberName] string name = "") + + #region Size And Window position + private double? _width = 800; + private double? _height = 600; + public double? Width + { + get => _width; + set => SetProperty(ref _width, value); + } + public double? Height + { + get => _height; + set => SetProperty(ref _height, value); + } + + public SizeToContent _sizeToContent = SizeToContent.Manual; + public SizeToContent SizeToContent + { + get => _sizeToContent; + set => _sizeToContent = value; + } + #endregion + + + /// <summary> + /// Needs to be called when a Property is changed + /// </summary> + /// + /// <param name="name">Is automatically set to CallerMemberName</param> + protected void OnPropertyChanged([CallerMemberName] string name = "") { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } @@ -45,6 +69,7 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common return propertyChanged; } + private string _title = GUILabels.DefaultTitle; public virtual string Title { get => _title; @@ -54,11 +79,10 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common [Inject] public IDialogHelper DialogHelper { get; set; } - protected bool AskForConfirmationOnClose { get; set; } = false; +#region Commands + protected bool AskForConfirmationOnClose { get; set; } = false; private ICommand _closeWindowCommand; - private string _title = GUILabels.DefaultTitle; - public ICommand CloseWindowCommand { get @@ -68,7 +92,8 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common } - protected void CloseWindow(Window window, IDialogHelper dialogHelper, bool showDialog = true) + + protected void CloseWindow(Window window, IDialogHelper dialogHelper, bool showDialog = true) { MessageBoxResult result; if (showDialog) { @@ -83,5 +108,6 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Common window?.Close(); } } + #endregion } } diff --git a/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs b/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs index 39808350ec312e252e4fee1d1df3624f39f19ff1..f998400748f53331737cf683f599bdce9d86954a 100644 --- a/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/Interfaces/Common/IViewModelBase.cs @@ -1,9 +1,13 @@ using System.ComponentModel; +using System.Windows; namespace VECTO3GUI2020.ViewModel.Interfaces.Common { public interface IViewModelBase : INotifyPropertyChanged { string Title { get; set; } + double? Width { get; set; } + double? Height { get; set; } + SizeToContent SizeToContent { get; set; } } } \ No newline at end of file diff --git a/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs b/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs index 897994d892efbe392c478575faf12f793db94f70..617c73368a9e179cbce1261d78591e48067103af 100644 --- a/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs +++ b/VECTO3GUI2020/ViewModel/Interfaces/IJobListViewModel.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using System.Windows.Input; using Microsoft.Toolkit.Mvvm.Input; +using NLog; using VECTO3GUI2020.Model.Interfaces; using VECTO3GUI2020.ViewModel.Interfaces.Document; @@ -14,12 +15,12 @@ namespace VECTO3GUI2020.ViewModel.Interfaces ICommand NewCompletedInputCommand { get; } ICommand NewExemptedCompletedInputCommand { get; } IRelayCommand NewVifCommand { get; } - IAsyncRelayCommand AddJobAsyncCommand { get; } ICommand EditDocument { get; set; } ICommand ViewXMLFile { get; set; } IAsyncRelayCommand RemoveJob { get; set; } ICommand OpenSourceFileCommand { get; } ICommand ShowSourceFileCommand { get; } + IAsyncRelayCommand AddJobAsyncCommand { get; } Task<IDocumentViewModel> AddJobAsync(string fileName, bool runSimulationAfterAdding = false); void AddJob(IDocumentViewModel jobToAdd); } diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs index 7d95cfe042db185567687c9655c99f6231fc8d1f..8f36c515544fe5990e7c2a672e3479b704b14b3d 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/CreateVifViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Windows; using System.Windows.Input; using Microsoft.Toolkit.Mvvm.Input; using TUGraz.VectoCommon.InputData; @@ -29,6 +30,7 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation _dialogHelper = dialogHelper; _inputDataReader = inputDataReader; Title = "Create VIF"; + SizeToContent = SizeToContent.WidthAndHeight; _documentName = $"New Vif {++_newVifCounter}"; }