Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多重绑定_C#_Wpf_Data Binding_Multibinding - Fatal编程技术网

C# 多重绑定

C# 多重绑定,c#,wpf,data-binding,multibinding,C#,Wpf,Data Binding,Multibinding,我有两个文本框,一个用于账单地址字段,另一个用于发货地址字段。当用户在“帐单地址”文本框中键入内容时,由于以下绑定场景,发货地址文本框将获得相同的值: <TextBox Name="txtBillingAddress" Text="{Binding BillingAddress, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" /> <TextBox Name="txtShippingAddress"> <

我有两个文本框,一个用于账单地址字段,另一个用于发货地址字段。当用户在“帐单地址”文本框中键入内容时,由于以下绑定场景,发货地址文本框将获得相同的值:

<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>

这在一定程度上是可行的。我还希望发货地址与账单地址一样绑定到我的数据库实体。我的问题是,虽然shipping address文本框中填充了账单地址中键入的内容,但在发生这种情况时,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; }
}

txtAddress控件位于多重绑定中的何处?你是想把txtBillingAddress放进去吗?是的,很抱歉给你弄糊涂了。我的情况有点复杂,所以我不能直接复制+粘贴。