我创建了一个简单的转换器来连接四个文本框的文本在我的WPF应用程序。

下面是转换器:

public class FourString:IMultiValueConverter
{
     public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
   {

       return string.Format("{0}{1}{2}{3}", values[0], values[1], values[2], values[3]);

   }
   public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
   {


       return new object[] {  };
   }

}

在XAML我使用此代码:

<local:FourString x:Key="converter"/>


  <TextBox  Grid.ColumnSpan="4"  Margin="95,7.5,71.25,3.75" Name="CodeBoatTxt" >
                            <TextBox.Text>
                                <MultiBinding Converter="{StaticResource converter}" >
                                    <Binding ElementName="CountryStringaTxt" Path="Text" />
                                    <Binding ElementName="CityStringaTxt" Path="Text" />
                                    <Binding ElementName="ServiceStringaTxt" Path="Text" />
                                    <Binding ElementName="DurationStringaTxt" Path="Text" />

                                </MultiBinding>
                            </TextBox.Text>
                        </TextBox>

当在调试,显示在文本框CodeBoatTxt此错误: “DependecyProperty.UnsetValue”

什么是错我的转换器?

有帮助吗?

解决方案

DependencyProperty.UnsetValue被传递到转换器当一个Binding是有效的,但不具有其值设置爱好。我会检查Bindings包括隔离您MultiBinding,并确保它们是正确的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top