If you do not want to use the converter, you can do it directly in your Property
INotifyChangedProperty Solution
private string _ImageID; public string ImageID { get { return _ImageID; } set { value = (value == null ? value : value.Trim()); NotifyPropertyChanged("ImageID"); } }
DependencyProperty Solution
public static readonly DependencyProperty ImageIDProperty = DependencyProperty.Register("ImageID", typeof(string), typeof(MainWindowViewModel), new PropertyMetadata(string.Empty)); public string ImageID { get { return (string)GetValue(ImageIDProperty); } set { SetValue(ImageIDProperty, value == null ? value : value.Trim()); } }
source share