I am trying to use both IMultiValueConverter
and StringFormat
.
It seems StringFormat
is ignored.
<code><?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
x:Class="MauiApp1.XmalMainPage"
Title="MainPage">
<Label FontSize="200">
<Label.Text>
<MultiBinding Converter="{local:MultiplyConverter}"
StringFormat="Evaluation: {0} * {1} = {2}">
<Binding Source="{x:Int32 3 }" />
<Binding Source="{x:Int32 5}" />
</MultiBinding>
</Label.Text>
</Label>
</ContentPage>
</code>
<code><?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
x:Class="MauiApp1.XmalMainPage"
Title="MainPage">
<Label FontSize="200">
<Label.Text>
<MultiBinding Converter="{local:MultiplyConverter}"
StringFormat="Evaluation: {0} * {1} = {2}">
<Binding Source="{x:Int32 3 }" />
<Binding Source="{x:Int32 5}" />
</MultiBinding>
</Label.Text>
</Label>
</ContentPage>
</code>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp1"
x:Class="MauiApp1.XmalMainPage"
Title="MainPage">
<Label FontSize="200">
<Label.Text>
<MultiBinding Converter="{local:MultiplyConverter}"
StringFormat="Evaluation: {0} * {1} = {2}">
<Binding Source="{x:Int32 3 }" />
<Binding Source="{x:Int32 5}" />
</MultiBinding>
</Label.Text>
</Label>
</ContentPage>
<code>public class MultiplyConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values.Length == 2 &&
double.TryParse(values[0]?.ToString(), out double x) &&
double.TryParse(values[1]?.ToString(), out double y))
{
//return $"Evaluation: {x} * {y} = {x*y}";
return x*y;
}
return "Error";
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
</code>
<code>public class MultiplyConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values.Length == 2 &&
double.TryParse(values[0]?.ToString(), out double x) &&
double.TryParse(values[1]?.ToString(), out double y))
{
//return $"Evaluation: {x} * {y} = {x*y}";
return x*y;
}
return "Error";
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
</code>
public class MultiplyConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (values.Length == 2 &&
double.TryParse(values[0]?.ToString(), out double x) &&
double.TryParse(values[1]?.ToString(), out double y))
{
//return $"Evaluation: {x} * {y} = {x*y}";
return x*y;
}
return "Error";
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}