2

WPFアプリで4つのTextBoxのテキストを連結するための単純なコンバーターを作成しました。

これがコンバーターです:

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」に表示されます。

コンバーターの何が問題になっていますか?

4

1 に答える 1

2

DependencyProperty.UnsetValueaが有効な場合にコンバーターに渡されBindingますが、値はまだ設定されていません。Binding私はあなたMultiBindingを単独で構成しているものをチェックし、それらが正しいことを確認します。

于 2009-08-25T09:04:06.293 に答える