Skip to content

Commit

Permalink
Fixed a class that checks the length of a custom processor or video c…
Browse files Browse the repository at this point in the history
…ard name
  • Loading branch information
TTLC198 committed Sep 9, 2023
1 parent 8550a94 commit 52c76bb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
15 changes: 8 additions & 7 deletions HSMonitor/Utils/ValidationRules/HardwareNameLengthRule.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

namespace HSMonitor.Utils.ValidationRules;

[ContentProperty("RuleValue")]
public class HardwareNameLengthRule: ValidationRule
{
public int Max { get; set; }

public int Min { get; set; }
public HardwareNameLengthRuleValue RuleValue { get; set; }

public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
try
{
if (((string)value).Length > Max)
if (((string)value).Length > RuleValue.Max)
return new ValidationResult(false,
$"Please enter a string less than {Max}.");
$"Please enter a string less than {RuleValue.Max}."); //todo localization

if (((string)value).Length < Min)
if (((string)value).Length < RuleValue.Min)
return new ValidationResult(false,
$"Please enter a string more than {Min}.");
$"Please enter a string more than {RuleValue.Min}.");
}
catch (Exception e)
{
Expand Down
30 changes: 30 additions & 0 deletions HSMonitor/Utils/ValidationRules/HardwareNameLengthRuleValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Windows;

namespace HSMonitor.Utils.ValidationRules;

public class HardwareNameLengthRuleValue : DependencyObject
{
public static readonly DependencyProperty MinBindingProperty = DependencyProperty.RegisterAttached(
nameof(Min),
typeof(int),
typeof(HardwareNameLengthRuleValue),
new PropertyMetadata(default(int))
);

public static readonly DependencyProperty MaxBindingProperty = DependencyProperty.RegisterAttached(
nameof(Max),
typeof(int),
typeof(HardwareNameLengthRuleValue),
new PropertyMetadata(default(int))
);

public int Min {
get => (int) GetValue(MinBindingProperty);
set => SetValue(MinBindingProperty, value);
}

public int Max {
get => (int) GetValue(MaxBindingProperty);
set => SetValue(MaxBindingProperty, value);
}
}

0 comments on commit 52c76bb

Please sign in to comment.