Hello,
is it possible to change the TrackballLabelTemplate (StringFormat) on a DateTimeAxis? At the moment the displayed label always has the format 'dd/MMM/yyyy'. But I need a format like dd.MM.yyyy HH:mm. How can I achieve this?
This is not working:
<DataTemplate x:Key="TrackballTemplate">
<Label BackgroundColor="Green" Text="{Binding StringFormat='{}{0:dd.MM.yyyy HH:mm}'}" TextColor="White" FontSize ="15" VerticalTextAlignment="Center"/>
</DataTemplate>
<xForms:DateTimeAxis TrackballLabelTemplate="{StaticResource TrackballTemplate}"....
...because BindingContext is already the formatted string.
Thanks in advance,
Robert
|
<chart:DateTimeAxis.LabelStyle>
<chart:ChartAxisLabelStyle LabelFormat="dd/MM/yyyy hh:mm:ss"/>
</chart:DateTimeAxis.LabelStyle> |
|
<DataTemplate x:Key="TrackballTemplate">
<Label BackgroundColor="Green" Text="{Binding Converter={StaticResource converter}}"
TextColor="White" FontSize ="15" VerticalTextAlignment="Center"/>
</DataTemplate> |
|
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
var date = System.Convert.ToDateTime(value.ToString());
value = date.ToString("dd.MM.yyyy HH:mm");
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
} |
|
<chart:DateTimeAxis LabelCreated="DateTimeAxis_LabelCreated"/> |
|
private void DateTimeAxis_LabelCreated(object sender, ChartAxisLabelEventArgs e)
{
var date = Convert.ToDateTime(e.LabelContent);
e.LabelContent = date.ToString("MMM-dd");
} |
|
<chart:DateTimeAxis.LabelStyle>
<chart:ChartAxisLabelStyle LabelFormat="dd/MM/yyyy hh:mm:ss"/>
</chart:DateTimeAxis.LabelStyle> |
|
private void DateTimeAxis_LabelCreated(object sender, ChartAxisLabelEventArgs e)
{
var date = Convert.ToDateTime(e.LabelContent);
e.LabelContent = date.ToString(viewModel.XLabelFormat);
} |