I’m able to style the AxisLabelContainerStyle and AxisLabelTemplate for my TimeSpanAxis but it doesn’t seem to be working for my NumericAxes/NumericAxisViewModels. Attached is a photo showing the styled TimeSpanAxis (cyan) and the default NumericAxis (green).
Here are the templates:
<Style TargetType="{x:Type sci:AxisLabelControl}" x:Key="CursorAxisLabelStyle">
<Setter Property="Background" Value="Black" />
</Style>
<DataTemplate DataType="{x:Type sci:AxisInfo}" x:Key="CursorNumericAxisLabelTemplate">
<Border BorderBrush="DarkCyan" BorderThickness="1">
<TextBlock Foreground="Cyan" Margin="2" Text="{Binding DataValue, StringFormat={}{0:0.0}}" />
</Border>
</DataTemplate>
<DataTemplate DataType="{x:Type sci:AxisInfo}" x:Key="CursorTimeSpanAxisLabelTemplate">
<Border BorderBrush="DarkCyan" BorderThickness="1">
<TextBlock Foreground="Cyan" Margin="2" Text="{Binding DataValue, StringFormat={}{0:hh}:{0:mm}:{0:ss}}" />
</Border>
</DataTemplate>
Here are the styles for the axes:
<Style TargetType="{x:Type sci:NumericAxis}">
<Setter Property="sci:CursorModifier.AxisLabelContainerStyle" Value="{StaticResource ResourceKey=CursorAxisLabelStyle}" />
<Setter Property="sci:CursorModifier.AxisLabelTemplate" Value="{StaticResource ResourceKey=CursorNumericAxisLabelTemplate}" />
</Style>
<Style TargetType="{x:Type sci:TimeSpanAxis}">
<Setter Property="sci:CursorModifier.AxisLabelContainerStyle" Value="{StaticResource ResourceKey=CursorAxisLabelStyle}" />
<Setter Property="sci:CursorModifier.AxisLabelTemplate" Value="{StaticResource ResourceKey=CursorTimeSpanAxisLabelTemplate}" />
</Style>
I will note that I’m binding my YAxes to an ObservableCollection because throws a binding error. But I’ve also tried using {x:Type sci:NumericAxisViewModel} which doesn’t work because it doesn’t derive from “FrameworkElement” and <x:Type sci:NumericAxisForMvvm} doesn’t style either.
I’m just not sure how to best make the NumericAxes styled.
Thanks!
- Greg Knox asked 3 years ago
- You must login to post comments
Hello Greg,
Have you tried to set to your style, some “x:Key”, like this
<Style TargetType="{x:Type sci:NumericAxis}" x:Key="MyAxisStyle">
<Setter Property="sci:CursorModifier.AxisLabelContainerStyle" Value="{StaticResource ResourceKey=CursorAxisLabelStyle}" />
<Setter Property="sci:CursorModifier.AxisLabelTemplate" Value="{StaticResource ResourceKey=CursorNumericAxisLabelTemplate}" />
</Style>
And then when you’re creating\assigning your AxisViewModel just assign this key as StyleKey, like this:
var numericAxis = new NumericAxisViewModel() { StyleKey = "MyAxisStyle" };
I’ve checked this in our examples suit, and can confirm that it’s working.
- Nazariy Pelyushkevych answered 3 years ago
- You must login to post comments
Please login first to submit.