I am trying to implement a wpf user control that binds a text box to a list of doubles using a converter. How can i set the instance of user control to be the converter parameter?
the code for the control is shown below
Thanks
<UserControl x:Class='BaySizeControl.BaySizeTextBox' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:local='clr-namespace:BaySizeControl' > <UserControl.Resources> <local:BayListtoStringConverter x:Key='BaySizeConverter'/> </UserControl.Resources> <Grid> <TextBox Name='Textbox_baysizes' Text='{Binding RelativeSource={RelativeSource self}, Path=Parent.Parent.BaySizeItemsSource, Converter={StaticResource BaySizeConverter}}' /> </Grid> </UserControl>
The parameters are for constants needed by your converter. To provide an object instance to your converter, you can use MultiBinding.
Note: For this solution to work, you also need to modify your converter to implement IMultiValueConverter instead of IValueConverter. Fortunately, the modifications involved are fairly little. You will can add a validation for the number of values provided to your converter, 2 in your case.