You could make the property's class implement INotifyPropertyChanged to update property notifications.
MainWindow.xaml.cs:
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
namespace TextChangedValidation
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
private double diceThreshold= 0.3;
public double DiceThreshold
{
get { return diceThreshold;}
set { diceThreshold=value; OnPropertyChanged("DiceThreshold");}
}
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
public class DoubleRangeRule : ValidationRule
{
public double Min { get; set; }
public double Max { get; set; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
double parameter = 0;
try
{
if (((string)value).Length > 0)
{
parameter = Double.Parse((String)value);
}
}
catch (Exception e)
{
return new ValidationResult(false, "Illegal characters or " + e.Message);
}
if ((parameter < this.Min) || (parameter > this.Max))
{
return new ValidationResult(false,
"Please enter value in the range: "
+ this.Min + " - " + this.Max + ".");
}
return new ValidationResult(true, null);
}
}
}
MainWindow.xaml:
196690-b.txt
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.