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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With