how to edit a WPF textbox which uses multibinding and string.format?

喜你入骨 提交于 2019-12-04 11:46:35

StringFormat binding is oneway

What you will need to do is write your own multivalue converter that implements the ConvertBack method as well.

A very simplistic converter would be something like below. You will need to add error checking and there is no doubtly a better way to convert back (possibly with a regex). Plus I'm not sure that I got the DateTime bit right but it gives you a starting point.

public class TimeConverter : IMultiValueConverter
 {
   public object Convert(object[] values, Type targetType, object parameter, 
      System.Globalization.CultureInfo culture)
   {
     return string.Format("{0}:{1}:{2}",values[0],values[1],values[2]);       }

  public object[] ConvertBack(object value, Type[] targetTypes, object parameter, 
      System.Globalization.CultureInfo culture)
   {
     var date=DateTime.Parse((string)value);
     return new object[] { date.Hours,date.Minutes,date.Seconds };

   }
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!