获得ConvertBack(来源值)在WPF的IValueConverter实现方法绑定 [英] Get the Source value in ConvertBack() method for IValueConverter implementation in WPF binding

查看:1105
本文介绍了获得ConvertBack(来源值)在WPF的IValueConverter实现方法绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绑定的依赖项属性在WPF中textboxex。该物业是具有以/(例如:1/2/3/4)分开一些值的字符串。我需要绑定个人价值分离的文本框这是很好用以下实施的转换()方法:

I am binding a dependency property to textboxex in WPF. The property is a string that has some values separated by '/' (example: "1/2/3/4" ). I need to bind individual values to separate textboxes which is fine with following implementation of Convert() method:

public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture)
{
  if (!string.IsNullOrEmpty(value as string))
  {
    String[] data = (value as string).Split('/');
    return data[Int16.Parse(parameter as string)];
  }
  return String.Empty;
}

和我使用的 ConverterParameter XAML 来指定需要的值的位置。
然而,问题是 ConvertBack()方法。我不知道,如何让源值,所以我可以只在字符串中增加或改变只是一个值(在指定位置)。

And I am using the ConverterParameter in xaml to specify the position of wanted value. However, the problem is with ConvertBack() method. I do not know, how to get the source value so I could just add or change just one value in the string (on the specified position).

感谢您的帮助。

推荐答案

在大多数情况下,你可以放心地 ConvertBack 只是把 NotImplementedException

In most cases, you can safely make ConvertBack just throw NotImplementedException.

事实上,你只是没有得到足够的信息来重新创建它的部分源值!

Indeed, you just haven't got enough information to recreate the source value from its part!

如果你真的需要回转换(例如,如果你使用双向绑定),我的财产分割为视图模型3串(在的DataContext ),并绑定到他们分开。

If you really need the back conversion (e.g., if you use two-direction binding), I would split the property into 3 strings in the view model (the class used in DataContext), and bind to them separately.

这篇关于获得ConvertBack(来源值)在WPF的IValueConverter实现方法绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆