SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

0
0

I’m wanting to apply an AxisLabelContainerStyle and AxisLabelTemplate to my YAxes which are of type NumericAxisViewModel.

My style and template:

<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="White" BorderThickness="1">
            <TextBlock Foreground="White" Margin="2" Text="{Binding DataValue, StringFormat={}{0:0.0}}" />
        </Border>
    </DataTemplate>

And I’ve tried the following with both TargetTypes NumericAxis and NumericAxisForMvvm. Using NumericAxisViewModel as the TargetType gives the error: “must derive from FrameworkElement or FrameworkContentElement.”

<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>

But neither of the two types (NumericAxis and NumericAxisForMvvm) seems to take on the style and template.

My XAxis is a TimeSpanAxis and the styles work just fine when applied there. (I have a different AxisInfo DataTemplate for the TimeSpanAxis.)

Any ideas on how I can apply those styles and templates to my YAxes? Thanks!

Version
6.2.1.13304
  • You must to post comments
0
0

Hi Greg

The process of applying a style to an Axis when using the MVVM api is as follows. First set a x:Key in your xaml on the axis style

<Style TargetType="{x:Type sci:NumericAxis}" x:Key="AxisStyle">
    <Setter Property="sci:CursorModifier.AxisLabelContainerStyle" Value="{StaticResource ResourceKey=CursorAxisLabelStyle}" />
    <Setter Property="sci:CursorModifier.AxisLabelTemplate" Value="{StaticResource ResourceKey=CursorNumericAxisLabelTemplate}" />
</Style>

Next, set the style key in your viewmodel as follows

var axis = new NumericAxisViewModel() { StyleKey = "AxisStyle" };

This will apply the style to the axis when using our MVVM API.

Let me know if this helps,

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.