WPF多绑定

8

我有两个文本框,一个用于账单地址,另一个用于发货地址。当用户在账单地址文本框中输入内容时,由于以下绑定场景,发货地址文本框会得到相同的值:

<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方法。只有在直接输入运输地址文本框时才会触发。

我错过了什么吗?


txtAddress控件在您的MultiBinding中位于哪里?您是不是想放置txtBillingAddress? - Jeff Wain
是的,抱歉让您感到困惑。我的情况比较复杂,所以我不能直接复制粘贴。 - David
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; }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接