My problem is that in some MAUI page I have a picker like so:
<Picker
x:Name="pickerTravelOrder"
Style="{StaticResource pickerStyle}"
HorizontalTextAlignment="Center"
FontSize="12"
SelectedIndex="0"
Title="{x:Static res:AppRes.TravelOrder}"
SelectedItem="{Binding ExpenseReport.TravelOrderID}"
ItemsSource ="{Binding TravelOrders}"
ItemDisplayBinding ="{Binding ., Converter={StaticResource TravelOrderPickerConverter}, Mode=TwoWay}"
SelectedIndexChanged="PickerTravelOrder_SelectedIndexChanged">
</Picker>
My converter is this:
public class TravelOrderPickerConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
TravelOrder model = value as TravelOrder;
if (model.Description == AppRes.None)
{
return $"--- {model.Description} ---";
}
else
{
return $"{model.Description} ({model.StartDate.ToShortDateString()} - {model.EndDate.ToShortDateString()})";
//return model.Description;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
//Go from "#{model.ID} [{model.Description}] [{model.StartDate.ToShortDateString()}]" to a TravelOrder:
try
{
//TODO
throw new NotImplementedException();
}
catch (Exception ex)
{
ErrorHandling.HandleError(ex);
return null;
}
}
}
I need to show in the selection list both the description (say, "Travel to Munich, Germany") and the interval, so people now what they are selecting. So in the end the picker should be populated with lines like "Travel to Munich, Germany (8/1/2024, 8/5/2024)"
On selecting a travelOrder, I populate two bound datepickers with the StartDate and EndDate so that these dates could be changed. At this point, the data is redundant - the interval is both in the description (in pickerTravelOrder) and in the two datePickers below.
How could I elegantly show in the picker the complete string "Travel to Munich, Germany (8/1/2024, 8/5/2024)" but, on selection, change the contents of that line to only "Travel to Munich, Germany"?