我有两个文本框,一个用于帐单地址字段,一个用于收货地址字段。当用户在帐单地址文本框中键入内容时,由于以下绑定(bind)情况,送货地址文本框将获得相同的值:
<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>
在某种程度上可以正常工作。我还希望将送货地址绑定(bind)到我的数据库实体,因为帐单邮寄地址是。我的问题是,在装船地址文本框中填充了在开单地址中键入的内容时,在这种情况下不会触发ConvertBack方法。仅在直接在收货地址文本框中键入内容时才会触发。
我想念什么?
最佳答案
也许这在您的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; }
}
关于c# - WPF多绑定(bind),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1168419/