Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 3ecf1711 authored by Harald Martini's avatar Harald Martini
Browse files

Added ViewModels (ManufacturingStageEditViewmodel,...

Added ViewModels (ManufacturingStageEditViewmodel, DeclarationInterimStageBusVehicleViewodel) and Views.

Added MultistageParameter Custom control
parent 907a945d
No related branches found
No related tags found
No related merge requests found
using System;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace VECTO3GUI2020.Views.CustomControls
{
public static class CustomControlExtensionMethods
{
/// <summary>
/// Looks up the Label by the name the Property that is used for the binding
/// </summary>
/// <param name="dependencyProperty"></param>
/// <param name="resourceManager"></param>
/// <returns></returns>
public static string GetLabelByPropertyName(this UserControl userControl, DependencyProperty dependencyProperty, ResourceManager resourceManager)
{
var name = "unresolved";
var Binding = userControl.GetBindingExpression(dependencyProperty);
var PropertyName = Binding?.ResolvedSourcePropertyName;
if (PropertyName == null || Binding == null)
{
return name;
}
var extendedPropertyName = Binding?.ResolvedSource.GetType().Name + "_" + PropertyName;
name = resourceManager?.GetString(extendedPropertyName) ?? resourceManager?.GetString(PropertyName) ?? (PropertyName + "_"); //_Postfix to label Property Names that are not in strings.resx
return name;
}
public static Type GetPropertyType(this UserControl userControl, DependencyProperty dependencyProperty)
{
var Binding = userControl.GetBindingExpression(dependencyProperty);
var PropertyName = Binding?.ResolvedSourcePropertyName;
if (PropertyName == null || Binding == null) {
return typeof(object);
}
var PropertyType = Binding?.ResolvedSource.GetType().GetProperty(PropertyName).PropertyType;
return PropertyType;
}
}
}
......@@ -67,7 +67,7 @@
<Button Command="{Binding AddJob}" Template="{DynamicResource MainViewButtonStyle}">OpenFile</Button>
<Button Command="{Binding EditJob}" Template="{DynamicResource MainViewButtonStyle}"
CommandParameter="{Binding ElementName=JobDataGrid, Path=SelectedItem}" Style="{DynamicResource MainViewButton}">EditFile</Button>
<Button Template="{DynamicResource MainViewButtonStyle}">NewFile</Button>
<Button Command="{Binding NewManufacturingStageFile}" Template="{DynamicResource MainViewButtonStyle}">New Multistage File</Button>
<Button Command="{Binding RemoveJob}" Template="{DynamicResource MainViewButtonStyle}"
CommandParameter="{Binding ElementName=JobDataGrid, Path=SelectedItem}">DeleteFile</Button>
</StackPanel>
......
<UserControl x:Class="VECTO3GUI2020.Views.Multistage.CustomControls.MultiStageParameter"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Name="MultistageParameterControl">
<Grid>
<!-- _____________________________________________ Text mode ___________________________________________________________________-->
<Grid Visibility="{Binding ElementName=MultistageParameterControl,
Path=ComboBoxMode,
Converter={StaticResource InvertedBoolToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" SharedSizeGroup="W"/>
<ColumnDefinition Width="1*" SharedSizeGroup="N"/>
<ColumnDefinition Width="4*" SharedSizeGroup="W"/>
<ColumnDefinition Width="4*" SharedSizeGroup="W"/>
<ColumnDefinition Width="1*" SharedSizeGroup="N"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding LabelText, ElementName=MultistageParameterControl}"></Label>
<CheckBox Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="CheckBox"
Visibility="{Binding Optional,
ElementName=MultistageParameterControl,
Converter={StaticResource BooleanToVisibilityConverter}}"
IsChecked="{Binding EditingEnabled,
ElementName=MultistageParameterControl,
Mode=TwoWay}"/>
<TextBox Grid.Column="2" VerticalAlignment="Center" Margin="2 0 2 0" IsReadOnly="True"
Visibility="{Binding Optional,
ElementName=MultistageParameterControl, Converter={StaticResource BooleanToVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox Grid.Column="3" Name ="TextBoxContent" VerticalAlignment="Center" Margin="2 0 2 0"
Text="{Binding Content,
ElementName=MultistageParameterControl }"
IsReadOnly="{Binding ElementName=MultistageParameterControl,
Path=EditingEnabled, Converter={StaticResource InvertBoolConverter}}"/>
<Label Grid.Column="4" x:Name="AutoUnitLabel"
Content="{Binding DummyContent, ElementName=MultistageParameterControl, Converter={StaticResource SIToUnitStringConverter}}">
</Label>
</Grid>
<!-- ______________________________________________ Comboboxmode ___________________________________________________-->
<Grid Visibility="{Binding ElementName=MultistageParameterControl,
Path=ComboBoxMode,
Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" SharedSizeGroup="W"/>
<ColumnDefinition Width="1*" SharedSizeGroup="N"/>
<ColumnDefinition Width="4*" SharedSizeGroup="W"/>
<ColumnDefinition Width="4*" SharedSizeGroup="W"/>
<ColumnDefinition Width="1*" SharedSizeGroup="N"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding LabelText, ElementName=MultistageParameterControl}"></Label>
<CheckBox Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Name="CheckBoxCombo"
Visibility="{Binding Optional,
ElementName=MultistageParameterControl,
Converter={StaticResource BooleanToVisibilityConverter}}"
IsChecked="{Binding EditingEnabled,
ElementName=MultistageParameterControl,
Mode=TwoWay}"/>
<ComboBox Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="2 0 2 0" Visibility="{Binding Optional,
ElementName=MultistageParameterControl,
Converter={StaticResource BooleanToVisibilityConverter}}" IsHitTestVisible="False" Focusable="False" IsEditable="False"/>
<ComboBox Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="2 0 2 0"
SelectedValue="{Binding Content, Mode=TwoWay, ElementName=MultistageParameterControl}"
ItemsSource="{Binding ListItems, ElementName=MultistageParameterControl}"
IsHitTestVisible="{Binding ElementName=MultistageParameterControl,
Path=EditingEnabled}"
Focusable="{Binding RelativeSource={RelativeSource Self},
Path=IsHitTestVisible}" IsEditable="False"/>
<Label Grid.Column="4"
Content="{Binding DummyContent, ElementName=MultistageParameterControl, Converter={StaticResource SIToUnitStringConverter}}">
</Label>
</Grid>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Castle.Components.DictionaryAdapter.Xml;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Utils;
using VECTO3GUI2020.Properties;
using VECTO3GUI2020.Views.CustomControls;
namespace VECTO3GUI2020.Views.Multistage.CustomControls
{
/// <summary>
/// Interaction logic for MultiStageParameter.xaml
/// </summary>
public partial class MultiStageParameter : UserControl
{
#region Dependency Properties
public static readonly DependencyProperty PreviousContentProperty = DependencyProperty.Register(
"PreviousContent", typeof(object), typeof(MultiStageParameter), new PropertyMetadata(default(object)));
public object PreviousContent
{
get { return (object)GetValue(PreviousContentProperty); }
set { SetValue(PreviousContentProperty, value); }
}
public static readonly DependencyProperty OptionalProperty = DependencyProperty.Register(
"Optional", typeof(bool), typeof(MultiStageParameter), new PropertyMetadata(true, new PropertyChangedCallback(OptionalChanged)));
private static void OptionalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MultiStageParameter multiStageParameter = (MultiStageParameter)d;
if ((bool)e.NewValue == false) {
multiStageParameter.EditingEnabled = true;
}
}
public bool Optional
{
get { return (bool)GetValue(OptionalProperty); }
set { SetValue(OptionalProperty, value); }
}
public static readonly DependencyProperty ComboBoxModeProperty = DependencyProperty.Register(
"ComboBoxMode", typeof(bool), typeof(MultiStageParameter), new PropertyMetadata(false));
public bool ComboBoxMode
{
get { return (bool)GetValue(ComboBoxModeProperty); }
set { SetValue(ComboBoxModeProperty, value); }
}
public static readonly DependencyProperty LabelTextProperty = DependencyProperty.Register(
"LabelText", typeof(string), typeof(MultiStageParameter), new PropertyMetadata(null));
public string LabelText
{
get { return (string)GetValue(LabelTextProperty); }
set { SetValue(LabelTextProperty, value); }
}
public static readonly DependencyProperty EditingEnabledProperty = DependencyProperty.Register(
"EditingEnabled", typeof(bool), typeof(MultiStageParameter), new FrameworkPropertyMetadata(
false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(EditingEnabledChanged)));
public bool EditingEnabled
{
get { return (bool)GetValue(EditingEnabledProperty);}
set
{
SetValue(EditingEnabledProperty, value);
}
}
public static readonly DependencyProperty DummyContentProperty = DependencyProperty.Register(
"DummyContent", typeof(object), typeof(MultiStageParameter), new PropertyMetadata(default(object)));
public object DummyContent
{
get { return (object)GetValue(DummyContentProperty); }
set { SetValue(DummyContentProperty, value); }
}
public static readonly DependencyProperty HideCheckBoxProperty = DependencyProperty.Register(
"HideCheckBox", typeof(bool), typeof(MultiStageParameter), new PropertyMetadata(default(bool)));
public bool HideCheckBox
{
get { return (bool)GetValue(HideCheckBoxProperty); }
set { SetValue(HideCheckBoxProperty, value); }
}
// Using a DependencyProperty as the backing store for MyObject. This enables animation, styling, binding, etc...
public new static readonly DependencyProperty ContentProperty =
DependencyProperty.Register("Content",
typeof(object),
typeof(MultiStageParameter),
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(ContentChanged))); //TODO Default value null breaks it for SIs default value "" for strings
public new object Content
{
get { return (object)GetValue(ContentProperty); }
set
{
SetCurrentValue(ContentProperty, value);
}
}
public static readonly DependencyProperty ListItemsProperty = DependencyProperty.Register(
"ListItems", typeof(List<object>), typeof(MultiStageParameter), new PropertyMetadata(default(List<object>)));
public List<object> ListItems
{
get { return (List<object>)GetValue(ListItemsProperty); }
set { SetValue(ListItemsProperty, value); }
}
#endregion
private static void ContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var multiStageParameter = (CustomControls.MultiStageParameter) d;
multiStageParameter.DummyContent = multiStageParameter.CreateDummyContent(e, multiStageParameter);
multiStageParameter.SetListItems();
if (multiStageParameter.LabelText != null) {
return;
}
multiStageParameter.LabelText = multiStageParameter.GetLabelByPropertyName(
MultiStageParameter.ContentProperty,
Strings.ResourceManager);
}
private void SetListItems()
{
if (!ComboBoxMode)
return;
if(DummyContent is Enum en) {
var enType = en.GetType();
ListItems = Enum.GetValues(enType).Cast<object>().ToList();
}
}
private object CreateDummyContent(DependencyPropertyChangedEventArgs e, UserControl userControl)
{
dynamic type = userControl.GetPropertyType(e.Property);
var baseType = type.BaseType;
try {
//Create SI Dummy
if (baseType == typeof(SI)) {
var createMethod = baseType.GetMethod("Create");
var dummyContent = createMethod?.Invoke(null, new object[] { (new double()) });
return dummyContent;
} else{
var bindingProperty = userControl.GetBindingExpression(e.Property);
var dataItemType = bindingProperty?.DataItem.GetType();
var sourcePropertyType =
dataItemType?.GetProperty(bindingProperty?.ResolvedSourcePropertyName)?.PropertyType;
var underlyingType = Nullable.GetUnderlyingType(type);
var dummyEnum = Enum.Parse(underlyingType, underlyingType.GetEnumNames()[0]);
return dummyEnum;
}
} catch (Exception ex) {
Debug.WriteLine(ex.Message);
return null;
}
return null;
}
private static void EditingEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MultiStageParameter multiStageParameter = (MultiStageParameter)d;
if ((bool)e.NewValue == false)
{
multiStageParameter.Content = null;
} else {
}
}
public MultiStageParameter()
{
InitializeComponent();
//LabelText = this.GetLabelByPropertyName(ContentProperty, Strings.ResourceManager);
}
}
}
<UserControl x:Class="VECTO3GUI2020.Views.Multistage.ManufacturingStageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage"
xmlns:implementation="clr-namespace:VECTO3GUI2020.ViewModel.MultiStage.Implementation"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid MaxWidth="900">
<Grid.RowDefinitions>
<RowDefinition Height="40px"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="30px"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox VerticalContentAlignment="Center" Height="Auto" Padding="4" Margin = "0 0 0 0" IsReadOnly="True"
Text="{Binding VifPath}" HorizontalAlignment="Stretch"/>
<Button Padding="4" Margin="4 0 0 0" Grid.Column="1" Command="{Binding AddVifFile}">
<Image Source="../../Resources/folderpicker.ico">
</Image>
</Button>
</Grid>
<ContentControl Grid.Row="1" Content="{Binding VehicleViewModel}"></ContentControl>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VECTO3GUI2020.Views.Multistage
{
/// <summary>
/// Interaction logic for InterimStageView.xaml
/// </summary>
public partial class ManufacturingStageView : UserControl
{
public ManufacturingStageView()
{
InitializeComponent();
}
}
}
<UserControl x:Class="VECTO3GUI2020.Views.Multistage.VehicleView_v2_8"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage"
xmlns:custom="clr-namespace:VECTO3GUI2020.Views.Multistage.CustomControls" xmlns:implementation="clr-namespace:VECTO3GUI2020.ViewModel.MultiStage.Implementation" d:DataContext="{d:DesignInstance Type=implementation:DeclarationInterimStageBusVehicleViewModel_v2_8}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" BorderBrush="Aquamarine" BorderThickness="2px" Margin="4px">
<Grid>
<StackPanel>
<Label Content="VEHICLE DATA" HorizontalAlignment="Stretch" Background="Aquamarine"/>
<custom:MultiStageParameter Optional="False" Content="{Binding Manufacturer}"/>
<custom:MultiStageParameter Optional="False" Content="{Binding ManufacturerAddress}"/>
<custom:MultiStageParameter Optional="False" Content="{Binding VIN}"/>
<custom:MultiStageParameter EditingEnabled="{Binding
MeasurementsGroupEditingEnabled}"
Content="{Binding Height}"/>
<custom:MultiStageParameter EditingEnabled="{Binding
MeasurementsGroupEditingEnabled}"
Content="{Binding Width}"
HideCheckBox="True"/>
<custom:MultiStageParameter EditingEnabled="{Binding
MeasurementsGroupEditingEnabled}"
Content="{Binding Length}"
HideCheckBox="True"/>
<custom:MultiStageParameter EditingEnabled="{Binding
NumberOfPassengersEditingEnabled}"
Content="{Binding NumberOfPassengersUpperDeck}"/>
<custom:MultiStageParameter EditingEnabled="{Binding
NumberOfPassengersEditingEnabled}"
Content="{Binding NumberOfPassengersLowerDeck}"
HideCheckBox="True"/>
<custom:MultiStageParameter Content="{Binding TankSystem}" ComboBoxMode="True"/>
</StackPanel>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VECTO3GUI2020.Views.Multistage
{
/// <summary>
/// Interaction logic for VehicleView_v2_8.xaml
/// </summary>
public partial class VehicleView_v2_8 : UserControl
{
public VehicleView_v2_8()
{
InitializeComponent();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment