Wpf Xaml。如何在不需要c代码的情况下对两个绑定求和

Wpf Xaml。如何在不需要c代码的情况下对两个绑定求和,wpf,xaml,Wpf,Xaml,我需要对wpf.xaml中的两个绑定(数字)求和,而不需要使用后端c#代码。这可行吗?如何可行 我有两个文本块,我需要将它们相加为第三个 <TextBlock x:Name="ChosenAmountValue" Grid.Row="0" Grid.Column="2" Style="{DynamicResource BalanceDisplayDetailText}" Text="{Binding _Transfer.TransferAmount , StringFormat=

我需要对wpf.xaml中的两个绑定(数字)求和,而不需要使用后端c#代码。这可行吗?如何可行

我有两个文本块,我需要将它们相加为第三个

    <TextBlock x:Name="ChosenAmountValue" Grid.Row="0" Grid.Column="2" 
Style="{DynamicResource BalanceDisplayDetailText}" Text="{Binding _Transfer.TransferAmount , StringFormat={}{0}.00}" IsEnabled="False" TextAlignment="Center" Background="Transparent"/>

    <TextBlock x:Name="SurchargeFeesValue" Grid.Row="2" Grid.Column="2"  Style="{DynamicResource BalanceDisplayDetailText}" Text="{Binding _Transfer.Fee.Value}" TextAlignment="Center" Background="Transparent"/>

    <TextBlock x:Name="SUM" Grid.Row="3" Grid.Column="3"  Style="{DynamicResource BalanceDisplayDetailText}"Text="{???}" TextAlignment="Center" Background="Transparent"/>


使用这样的转换器。
class ValuesAdditionConverter:IMultiValueConverter
{
公共对象转换(对象[]值,类型targetType,对象参数,CultureInfo区域性)
{
返回(int)值[0]+(int)值[1];
}
公共对象[]转换回(对象值,类型[]目标类型,对象参数,CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}

您是否意识到拥有转换器实际上是c代码,因此它违背了答案的目的?很抱歉,很遗憾,我无法使用c代码,我正在尝试从现有转换器或任何其他工作环境中执行此操作。您可以访问什么?因为最简单的方法是为此使用单独的属性,第二种最简单的方法是使用转换器(自定义或)。XAML不是逻辑的最佳场所,它不打算进行这样的操作(尽管可能有一种方法)。
 <UserControl.Resources>
     <converters:ValuesAdditionConverter x:Key="ValuesAddition" />
 </UserControl.Resources>

 <TextBlock x:Name="ChosenAmountValue" Grid.Row="0" Grid.Column="2" Style="{DynamicResource BalanceDisplayDetailText}" Text="{Binding _Transfer.TransferAmount , StringFormat={}{0}.00}" IsEnabled="False" TextAlignment="Center" Background="Transparent"/>
 <TextBlock x:Name="SurchargeFeesValue" Grid.Row="2" Grid.Column="2"  Style="{DynamicResource BalanceDisplayDetailText}" Text="{Binding _Transfer.Fee.Value}" TextAlignment="Center" Background="Transparent"/>
 <TextBlock x:Name="SUM" Grid.Row="3" Grid.Column="3"  Style="{DynamicResource BalanceDisplayDetailText}" 
    TextAlignment="Center" Background="Transparent">
          <TextBlock.Text>
              <MultiBinding Converter="{StaticResource ValuesAddition}" >
                   <Binding Path="_Transfer.TransferAmount"/>
                    <Binding Path=" _Transfer.Fee.Value" />
              </MultiBinding>
          </TextBlock.Text>
 </TextBlock>

and use a converter like this.

class ValuesAdditionConverter : IMultiValueConverter
{
     public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
     {
         return (int)values[0] + (int)values[1];
     }

     public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
     {
         throw new NotImplementedException();
     }
}