[ValueConversion(typeof(DateTime), typeof(String))] public class DateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return "now is "+date.ToString(); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string strValue = value.ToString(); DateTime resultDateTime; if (DateTime.TryParse(strValue, out resultDateTime)) { return resultDateTime; } return value; } }
public class MenuButtonModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
private bool? _hasFocus; public bool? HasFocus { get { return _hasFocus; } set { _hasFocus = value; NotifyPropertyChanged("HasFocus"); } }
private string _iconPath; public string IconPath { get { return _iconPath; } set { _iconPath = value; NotifyPropertyChanged("IconPath"); } } }
对应Flex的实现:
[Bindable] public class MenuButtonModel : IEventDispatcher { public var hasFocus:Boolean; public var iconPath:String; }
[ValueConversion(typeof(DateTime), typeof(String))] public class DateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return "now is "+date.ToString(); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string strValue = value.ToString(); DateTime resultDateTime; if (DateTime.TryParse(strValue, out resultDateTime)) { return resultDateTime; } return value; } }
public class MenuButtonModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
private bool? _hasFocus; public bool? HasFocus { get { return _hasFocus; } set { _hasFocus = value; NotifyPropertyChanged("HasFocus"); } }
private string _iconPath; public string IconPath { get { return _iconPath; } set { _iconPath = value; NotifyPropertyChanged("IconPath"); } } }
对应Flex的实现:
[Bindable] public class MenuButtonModel : IEventDispatcher { public var hasFocus:Boolean; public var iconPath:String; }