Update
You probably solved your problem already with the help of Vlad, I just thought that I should add another way to get the original value in the converter.
First you can make your converter from DependencyObject so that you can add a dependency property to it, which we will associate with
public class MyConverter : DependencyObject, IValueConverter { public static DependencyProperty SourceValueProperty = DependencyProperty.Register("SourceValue", typeof(string), typeof(MyConverter)); public string SourceValue { get { return (string)GetValue(SourceValueProperty); } set { SetValue(SourceValueProperty, value); } } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
Unfortunately, the converter does not have a DataContext , so the binding will not work out of the box, but you can use Josh Smith perfectly DataContextSpy : Artifical inheritance contexts in WPF
<TextBox> <TextBox.Resources> <src:DataContextSpy x:Key="dataContextSpy" /> </TextBox.Resources> <TextBox.Text> <Binding Path="YourProperty" ConverterParameter="1"> <Binding.Converter> <src:MyConverter SourceValue="{Binding Source={StaticResource dataContextSpy}, Path=DataContext.YourProperty}"/> </Binding.Converter> </Binding> </TextBox.Text> </TextBox>
End of update
Dr.WPF has an elegant solution for this, see the following chain
How to access binding source in ConvertBack ()?
Edit
Using the Dr.WPF solution, you can specify both the line index and the TextBox source to converter using this (possibly a little detailed) code example
<TextBox dw:ObjectReference.Declaration="{dw:ObjectReference textBoxSource}"> <TextBox.Text> <Binding Path="YourStringProperty" Converter="{StaticResource YourConverter}"> <Binding.ConverterParameter> <x:Array Type="sys:Object"> <sys:Int16>1</sys:Int16> <dw:ObjectReference Key="textBoxSource"/> </x:Array> </Binding.ConverterParameter> </Binding> </TextBox.Text> </TextBox>
And then you can later access both the index and the TextBox in the ConvertBack method
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { object[] parameters = parameter as object[]; short index = (short)parameters[0]; object source = (parameters[1] as TextBox).DataContext;