我有两个文本框,一个帐单地址字段和一个用于送货地址字段。当用户键入的东西到帐单地址文本框中输入送货地址文本框中获取相同的值,由于以下绑定方案:

<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方法不同时,这种情况正在发生解雇。如果事情是直接键入送货地址文本框中它只是解雇了。

我是什么失踪?

有帮助吗?

解决方案

也许这会更容易在您的视图模型来实现?

public string BillingAddress{
    set{
        billingAddress = value;
        firePropertyChanged("BillingAddress");
        if(string.isNullOrEmpty(ShippingAddress)
        {
            ShippingAddress = value; //use the property to ensure PropertyChanged fires
        }
    }
    get{ return billingAddress; }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top