Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF TextBox.Text with MultiBinding

I've got Custom Control with a TextBox in the default Template. The Custom Control has these 2 dependency properties (among others):

SelectedValue, NullText (text to appear in the TextBox when nothing is selected and the value is provided)

I'd like to set the TextBox.Text with the NullText value when the SelectedValue null is and the NullText not null is.

<TextBox.Text>                                              
 <MultiBinding Converter="{StaticResource myConverter}">
   <Binding RelativeSource="TemplatedParent" Path="SelectedValue"/>
   <Binding RelativeSource="TemplatedParent" Path="NullText"/>
 </MultiBinding>                                              
</TextBox.Text>

I've got a IMultiValueConverter:

public class MyConverter : IMultiValueConverter
{}

With this XAML definition I got 'type does not have a public TypeConverter class' Exception

How would you solve it, please?

like image 977
theSpyCry Avatar asked Feb 02 '10 15:02

theSpyCry


1 Answers

I found the SOLUTION by myself: The problem was with the RelativeSource. This is how it should look like:

<TextBox.Text>                                              
 <MultiBinding Converter="{StaticResource myConverter}">
   <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="SelectedValue"/>
   <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="NullText"/>
 </MultiBinding>                                              
</TextBox.Text>
like image 160
theSpyCry Avatar answered Nov 15 '22 21:11

theSpyCry