Dav*_*vid 8 c# data-binding wpf multibinding
我有两个文本框,一个用于帐单地址字段,另一个用于送货地址字段.当用户在"帐单邮寄地址"文本框中键入内容时,由于以下绑定方案,送货地址文本框会获得相同的值:
<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>
Run Code Online (Sandbox Code Playgroud)
这在一定程度上可行.我还希望将送货地址绑定到我的数据库实体,因为帐单地址是.我的问题是,虽然发货地址文本框中填充了帐单地址中输入的内容,但在发生这种情况时不会触发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; }
}
Run Code Online (Sandbox Code Playgroud)