1using System;2using System.Collections.Generic;3using System.ComponentModel;4using System.Runtime.CompilerServices;56namespace WpfApp1
7{8 public class ViewModel : INotifyPropertyChanged
9{10#regionINotifyPropertyChanged11 public event PropertyChangedEventHandler PropertyChanged;12 protected virtual voidOnPropertyChanged(string propertyName)13{14 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));15}16 protected bool SetProperty<T>(ref T field, T value,[CallerMemberName]string propertyName = null)17{18if(EqualityComparer<T>.Default.Equals(field, value))return false;19 field = value;20OnPropertyChanged(propertyName);21return true;22}23#endregion2425 private string textValue;26 public string TextValue
27{28 get => textValue;29 set
30{31if(DateTime.TryParse(value, out DateTime dateTime))32{33 value = dateTime.ToString("yyyy/MM/dd");34}35elseif(int.TryParse(value, out int i))36{37 value = i.ToString("N0");38}39elseif(double.TryParse(value, out double d))40{41 value = d.ToString("N2");42}43SetProperty(ref textValue, value);44}45}46}47}