Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. public class TextToPasswordCharConverter : IValueConverter
  2. {
  3. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  4. {
  5. var str = new string('*', value?.ToString().Length ?? 0);
  6. return str;
  7. }
  8.  
  9. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  10. {
  11. //throw new NotImplementedException();
  12. return new object();
  13. }
  14. }
  15.  
  16. public string PasswordField
  17. {
  18. get => passwordValue;
  19. set
  20. {
  21. passwordValue = value;
  22. OnPropertyChanged();
  23. }
  24. }
  25.  
  26. public abstract class NotificationObject : INotifyPropertyChanged
  27. {
  28. public event PropertyChangedEventHandler PropertyChanged;
  29.  
  30. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  31. {
  32. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  33. }
  34.  
  35. protected void SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
  36. {
  37. if (!EqualityComparer<T>.Default.Equals(field, value))
  38. {
  39. field = value;
  40. OnPropertyChanged(propertyName);
  41. }
  42. }
  43. }
  44.  
  45. <TextBox Grid.Row="0" Grid.Column="0" TextWrapping="Wrap" Margin="140,174,30,10">
  46. <TextBox.Text>
  47. <Binding Path="PasswordField" ValidatesOnDataErrors="True" Converter="{StaticResource TextToPasswordCharConverter}" UpdateSourceTrigger="PropertyChanged">
  48. <Binding.ValidationRules>
  49. <ExceptionValidationRule />
  50. </Binding.ValidationRules>
  51. </Binding>
  52. </TextBox.Text>
  53. </TextBox>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement