Xaml。如何总结两个绑定,而不需要c#代码
问题描述:
我需要在wpf .xaml中总结两个绑定(数字),而不需要使用后端c#代码。这是可行的,以及如何?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"/>
答
<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();
}
}
+0
你知道有一个转换器实际上是C#代码,所以它打败了答案的目的? – Noctis
+0
很抱歉,不幸的是我不能使用C#代码,我试图从现有的转换器或任何其他方法 –
你有什么访问?因为最简单的方法是为此拥有一个单独的属性,第二个最简单的方法是有一个转换器(自定义或[第三方](http://*.com/questions/3572432/can-i-add-subtract-值 - 即 - 被结合到一个元素属性))。 XAML不是最适合逻辑的地方,它不打算做这样的操作(尽管可能有一种方法)。 – icebat