簡體   English   中英

WPF多綁定

[英]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>

在某種程度上可以正常工作。 我也希望將送貨地址綁定到我的數據庫實體,因為帳單地址是這樣。 我的問題是,在裝船地址文本框中填充了在開單地址中鍵入的內容時,在這種情況下不會觸發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; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM