8

請求先住所フィールド用と配送先住所フィールド用の 2 つのテキスト ボックスがあります。ユーザーが請求先住所のテキスト ボックスに何かを入力すると、次のバインディング シナリオにより、配送先住所のテキスト ボックスは同じ値になります。

<TextBox Name="txtBillingAddress" Text="{Binding BillingAddress, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

<TextBox Name="txtShippingAddress">
   <TextBox.Text>
      <MultiBinding Converter="{StaticResource AddressConverter}">
         <Binding ElementName="txtBillingAddress" Path="Text" Mode="OneWay" />
         <Binding Path="ShippingAddress" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" />
      </MultiBinding>
   </TextBox.Text>
</TextBox>

これは、ある程度までは正常に機能します。また、請求先住所と同様に、配送先住所をデータベース エンティティにバインドしたいと考えています。私の問題は、請求先住所に入力された内容が配送先住所テキスト ボックスに入力されている間、これが発生している間は ConvertBack メソッドが起動されないことです。配送先住所のテキスト ボックスに何かが直接入力された場合にのみ発生します。

私は何が欠けていますか?

4

1 に答える 1

5

これを ViewModel に実装する方が簡単ではないでしょうか?

public string BillingAddress{
    set{
        billingAddress = value;
        firePropertyChanged("BillingAddress");
        if(string.isNullOrEmpty(ShippingAddress)
        {
            ShippingAddress = value; //use the property to ensure PropertyChanged fires
        }
    }
    get{ return billingAddress; }
}
于 2009-07-23T08:56:11.533 に答える