WPF TextBox.Text with MultiBinding

▼魔方 西西 提交于 2019-12-22 04:43:34

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/2185168/wpf-textbox-text-with-multibinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!