From bf432bf7b7faa7c51e74462e19eb3e50c28b4aa8 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 22 Jan 2020 18:00:55 +0200 Subject: Implemented StringFormat control for db properties. Added StringFormat 0.000 for FeederTension on ProcessParameters. --- .../CustomAttributes/StringFormatAttribute.cs | 24 ++++++++++++++++++++++ .../ExtensionMethods/IParameterizedExtensions.cs | 7 +++++++ Software/Visual_Studio/Tango.Core/ParameterItem.cs | 13 ++++++++++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 3 ++- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/Tango.Core/CustomAttributes/StringFormatAttribute.cs (limited to 'Software/Visual_Studio/Tango.Core') diff --git a/Software/Visual_Studio/Tango.Core/CustomAttributes/StringFormatAttribute.cs b/Software/Visual_Studio/Tango.Core/CustomAttributes/StringFormatAttribute.cs new file mode 100644 index 000000000..e7089b64d --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/CustomAttributes/StringFormatAttribute.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.CustomAttributes +{ + [AttributeUsage(AttributeTargets.Property)] + public class StringFormatAttribute : Attribute + { + public String Format { get; set; } + + public StringFormatAttribute() + { + Format = "0.0"; + } + + public StringFormatAttribute(String format) : this() + { + Format = format; + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs index 7107b9ee9..4850ccc25 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using Tango.Core; +using Tango.Core.CustomAttributes; /// /// Contains extension methods for . @@ -112,6 +113,12 @@ public static class IParameterizedExtensions item.Minimum = rangeAtt.Minimum; item.Maximum = rangeAtt.Maximum; } + + StringFormatAttribute formatAtt = propertyInfo.GetCustomAttribute(); + if (formatAtt != null) + { + item.StringFormat = formatAtt.Format; + } } if (mode == ParameterItemMode.Event) diff --git a/Software/Visual_Studio/Tango.Core/ParameterItem.cs b/Software/Visual_Studio/Tango.Core/ParameterItem.cs index ee7acfdd0..0ce682e01 100644 --- a/Software/Visual_Studio/Tango.Core/ParameterItem.cs +++ b/Software/Visual_Studio/Tango.Core/ParameterItem.cs @@ -137,6 +137,19 @@ namespace Tango.Core DependencyProperty.Register("Description", typeof(String), typeof(ParameterItem), new PropertyMetadata(null)); + /// + /// Gets or sets the parameter string format. + /// + public String StringFormat + { + get { return (String)GetValue(StringFormatProperty); } + set { SetValue(StringFormatProperty, value); } + } + public static readonly DependencyProperty StringFormatProperty = + DependencyProperty.Register("StringFormat", typeof(String), typeof(ParameterItem), new PropertyMetadata("0.0")); + + + /// /// Gets a value indicating whether this instance requires custom editor. /// diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 54d7e3259..1dc51c2cf 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -89,6 +89,7 @@ GlobalVersionInfo.cs + @@ -200,7 +201,7 @@ - + -- cgit v1.3.1