WPF MultiBinding
Asked Answered
O

1

8

I have two text boxes, one for a billing address field and one for a shipping address field. When the user types something into the the billing address text box the shipping address text box gets the same value due to the following binding scenario:

<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>

This works fine up to a point. I also want the shipping address to be bound to my database entity as the billing address is. My problem is that while the shipping address text box is populated with what is typed in the billing address, the ConvertBack method is not fired while this is happening. It is only fired if something is typed directly into the shipping address text box.

What am I missing?

Offen answered 22/7, 2009 at 21:39 Comment(2)
where does the txtAddress control reside in your MultiBinding? Did you mean to put txtBillingAddress?Close
Yes, sorry for the confusion. My situation is a bit more complex so I couldn't do a direct copy+paste.Offen
S
5

Maybe this would be easier to implement in your 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; }
}
Serval answered 23/7, 2009 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.