Hi
I want to override the default AxisLabelTemplate for a DateTimeAxis beyond the normal circumstances.
Setting the AxisLabelTemplate to a StaticResource is easy enough, but all I have inside the Template is the CursorFormattedDataValue and I want to be able to send in something more then a simple string.
<ControlTemplate x:Key="RolloverModifierAxisLabelTemplateDefault">
<Border Background="LightGray"
Opacity="0.80"
BorderThickness="0"
CornerRadius="5"
Padding="2"
Visibility="{Binding IsXAxis, Converter={StaticResource BoolToVisibilityConverter}}">
<TextBlock Text="{Binding CursorFormattedDataValue}" />
</Border>
</ControlTemplate>
Extending the LabelProviderBase gives me the opportunity to override the FormatCursorLabel method, but it only returns a string and not an object and therefore I can not pass my own data structure to be used inside the AxisLabelTemplate.
How can we solve this issue? Is there a workaround, or is this something you need to implement?
- Sander Struijk asked 10 years ago
- You must login to post comments
Hi Sander,
We’ve investigated the issue and done slight changes in order to allow creating a custom AxisInfo. You should derive your own type from AxisInfo, it will act as a ViewModel. Then override the HitTest method on an axis, create and initialize the instance of that type there and return it.
So if you try out the nightly build tomorrow, the following code should do the trick:
public class CustomAxis : NumericAxis
{
public override AxisInfo HitTest(IComparable dataValue)
{
var result = new CustomAxisInfo { MyProperty1 = "MyProperty1", MyProperty2 = "MyProperty2" };
var axisInfo = base.HitTest(dataValue);
// Copy all the values from axisInfo here
return result;
}
}
public class CustomAxisInfo : AxisInfo
{
public string MyProperty1 { get; set; }
public string MyProperty2 { get; set; }
}
And here is a label template sample:
<ControlTemplate x:Key="AxisLabelTemplate" TargetType="s:TemplatableControl">
<Grid>
<Rectangle Width="100" Height="50" Fill="Yellow"/>
<TextBlock Text="{Binding MyProperty1}"/>
</Grid>
</ControlTemplate>
Also we will consider if we can provide a bit more convenient way to do this in next versions, for instance via a custom LabelProvider.
Please let us know your thoughts about this solution,
Best regards,
Yuriy
- Guest answered 10 years ago
- Looks good and thanks for fast response! I will try this out tomorrow then. I also agree that for future versions this could be streamlined a bit more with a LabelProvider or something.
- You must login to post comments
Please login first to submit.