From 75fbf19d1414e952b72b2ff782b8daf722680721 Mon Sep 17 00:00:00 2001 From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at> Date: Thu, 15 Jul 2021 14:03:08 +0200 Subject: [PATCH] Added parameters to ProeprtyNameToLabelTextConverter --- .../PropertyNameToLabelTextConverter.cs | 32 +++++++++++++++++-- VECTO3GUI2020/Resources/ObjectProvider.xaml | 1 - .../AdditionalJobInfoViewMultiStage.xaml | 18 +++++++++-- .../AdditionalJobInfoViewNewVIF.xaml | 17 +++++++++- 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/VECTO3GUI2020/Helper/Converter/PropertyNameToLabelTextConverter.cs b/VECTO3GUI2020/Helper/Converter/PropertyNameToLabelTextConverter.cs index 5f1f6d49b4..e164d620ae 100644 --- a/VECTO3GUI2020/Helper/Converter/PropertyNameToLabelTextConverter.cs +++ b/VECTO3GUI2020/Helper/Converter/PropertyNameToLabelTextConverter.cs @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; using System.Globalization; +using System.Linq; +using System.Resources; using System.Windows.Data; using VECTO3GUI2020.Properties; @@ -8,10 +11,35 @@ namespace VECTO3GUI2020.Helper.Converter public class PropertyNameToLabelTextConverter : IValueConverter { #region Implementation of IValueConverter - + /// <summary> + /// Maps the value to a string found in the given ResourceFiles (first match). + /// + /// </summary> + /// <param name="value"></param> + /// <param name="targetType"></param> + /// <param name="parameter"></param> + /// <param name="culture"></param> + /// <example> + /// + /// <Binding Path="." Converter="{StaticResource PropertyNameToLabelConverter}"> + /// <Binding.ConverterParameter> + /// <x:Array Type="resources:ResourceManager"> + /// <x:Static MemberType="properties:Strings" Member="ResourceManager"/> + /// </x:Array> + /// </Binding.ConverterParameter> + /// </Binding> + /// + /// </example> + /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - return NameResolver.ResolveName(value as string, BusStrings.ResourceManager, Strings.ResourceManager) ?? Binding.DoNothing; + if (parameter is IEnumerable<ResourceManager> resourceManagers) { + return NameResolver.ResolveName(value as string, resourceManagers.ToArray()); + } else { + return NameResolver.ResolveName(value as string, BusStrings.ResourceManager, Strings.ResourceManager) ?? Binding.DoNothing; + } + + } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/VECTO3GUI2020/Resources/ObjectProvider.xaml b/VECTO3GUI2020/Resources/ObjectProvider.xaml index 1c858f64f6..91185b8f68 100644 --- a/VECTO3GUI2020/Resources/ObjectProvider.xaml +++ b/VECTO3GUI2020/Resources/ObjectProvider.xaml @@ -7,5 +7,4 @@ ObjectType="{x:Type helper:ConvertedSIDummyCreator}" MethodName="CreateMillimeterDummy"/> - <ObjectDataProvider x:Key="BusStringResourceManager" ObjectType="{x:Type resources:ResourceManager}" ObjectInstance="{x:Static properties:BusStrings.ResourceManager}"/> </ResourceDictionary> \ No newline at end of file diff --git a/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewMultiStage.xaml b/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewMultiStage.xaml index 89708c6bc8..8c2b7dab7a 100644 --- a/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewMultiStage.xaml +++ b/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewMultiStage.xaml @@ -5,6 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VECTO3GUI2020.Views.Multistage.AdditionalJobInfoViews" xmlns:common="clr-namespace:VECTO3GUI2020.ViewModel.Implementation.Common" + xmlns:resources="clr-namespace:System.Resources;assembly=mscorlib" + xmlns:properties="clr-namespace:VECTO3GUI2020.Properties" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance common:AdditionalJobInfoViewModelMultiStage }"> <Grid> @@ -15,9 +17,21 @@ <DataTemplate> <BulletDecorator> <BulletDecorator.Bullet> - <Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Height="5" Width="5" Fill="{DynamicResource AccentColorButton}"></Ellipse> + <Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Height="5" Width="5" Fill="{DynamicResource AccentColorButton}"/> </BulletDecorator.Bullet> - <TextBlock Margin="5 0" Text="{Binding Converter={StaticResource PropertyNameToLabelConverter}}"></TextBlock> + <TextBlock Margin="5 0"> + <TextBlock.Text> + <Binding Path="." Converter="{StaticResource PropertyNameToLabelConverter}"> + <Binding.ConverterParameter> + <x:Array Type="resources:ResourceManager"> + <x:Static MemberType="properties:GUILabels" Member="ResourceManager"/> + <x:Static MemberType="properties:BusStrings" Member="ResourceManager"/> + <x:Static MemberType="properties:Strings" Member="ResourceManager"/> + </x:Array> + </Binding.ConverterParameter> + </Binding> + </TextBlock.Text> + </TextBlock> </BulletDecorator> </DataTemplate> </ItemsControl.ItemTemplate> diff --git a/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewNewVIF.xaml b/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewNewVIF.xaml index 43c386f4c1..c29c356e53 100644 --- a/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewNewVIF.xaml +++ b/VECTO3GUI2020/Views/Multistage/AdditionalJobInfoViews/AdditionalJobInfoViewNewVIF.xaml @@ -4,6 +4,8 @@ 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.AdditionalJobInfoViews" + xmlns:properties="clr-namespace:VECTO3GUI2020.Properties" + xmlns:resources="clr-namespace:System.Resources;assembly=mscorlib" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> <Grid> @@ -16,7 +18,20 @@ <BulletDecorator.Bullet> <Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Height="5" Width="5" Fill="{DynamicResource AccentColorButton}"></Ellipse> </BulletDecorator.Bullet> - <TextBlock Margin="5 0" Text="{Binding Converter={StaticResource PropertyNameToLabelConverter}}"></TextBlock> + <TextBlock Margin="5 0"> + <TextBlock.Text> + <Binding Path="." Converter="{StaticResource PropertyNameToLabelConverter}"> + <Binding.ConverterParameter> + <x:Array Type="resources:ResourceManager"> + <x:Static MemberType="properties:GUILabels" Member="ResourceManager"/> + <x:Static MemberType="properties:BusStrings" Member="ResourceManager"/> + <x:Static MemberType="properties:Strings" Member="ResourceManager"/> + </x:Array> + </Binding.ConverterParameter> + </Binding> + </TextBlock.Text> + </TextBlock> + </BulletDecorator> </DataTemplate> </ItemsControl.ItemTemplate> -- GitLab