Наконец-то я нашел способ реализовать эти функции. Использование конвертера.
public class AddListRecordsConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
decimal val = 0;
decimal result = 0;
foreach (var txt in values)
{
if (string.IsNullOrEmpty(txt.ToString())) continue;
if (decimal.TryParse(txt.ToString(), out val))
result += val;
else
return "$0.00";
}
return result.ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
public class InterestCalculationRecordsConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
decimal val = 0;
decimal result = 0;
List<decimal> convertedLists = new List<decimal>();
foreach (var txt in values)
{
if (string.IsNullOrEmpty(txt.ToString())) return null;
if (decimal.TryParse(txt.ToString(), out val))
//result += val;
convertedLists.Add(val);
else
return "$0.00";
}
if (convertedLists[0] == 0) return 0;
result = 1 / convertedLists[0] * convertedLists[1] * convertedLists[2] * convertedLists[3];
return result.ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
Xaml похож на ниже.
<Page.Resources>
<local:AddListRecordsConverter x:Key="AddListRecordsConverter"></local:AddListRecordsConverter>
<local:InterestCalculationRecordsConverter x:Key="InterestCalculationRecordsConverter"></local:InterestCalculationRecordsConverter>
</Page.Resources>
Текстовое поле Xaml похоже на ниже (просто отправьте вычисления int):
<TextBox Grid.Row="7" Grid.Column="2" Name="TxtPostJudgmentInterest" IsEnabled="False">
<TextBox.Text>
<MultiBinding Converter="{StaticResource InterestCalculationRecordsConverter}">
<Binding ElementName="TxtYearDays" Path="Text" Mode="OneWay"></Binding>
<Binding ElementName="TxtDays" Path="Text" Mode="OneWay"></Binding>
<Binding ElementName="TxtPrincipal" Path="Text" Mode="OneWay"></Binding>
<Binding ElementName="TxtInt" Path="Text" Mode="OneWay"></Binding>
</MultiBinding>
</TextBox.Text>
</TextBox>