Pre loader

Axes added from ViewModel, set style from XAML

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
1
0

Hi,

I’m using MVVM to dynamically add axes in the runtime with a binding to YAxes and XAxes from the SciChartSurface. like this,

<s:SciChartSurface XAxes="{Binding XAxes}" YAxes="{Binding YAxes}"/>

The problem is, since I’m creating and adding these from the ViewModel, my “AxisStyle” style (defined inside UserControl.Resources) does not automatically apply to my axes. Initially I had the style in my Resources file, which I can access from the ViewModel and manually apply it from the code.

The reason I’m changing the style’s location from Resources.xaml to the control itself is this;

 <Style x:Key="AxisStyle" TargetType="SciChart:AxisBase">
            <Setter Property="TickTextBrush" Value="{Binding GraphThemeOptions.LabelBrush}"/>
            <Setter Property="MinorTickLineStyle">
                <Setter.Value>
                    <Style TargetType="Line">
                        <Setter Property="Stroke" Value="{Binding GraphThemeOptions.LabelBrush"/>
                    </Style>
                </Setter.Value>
            </Setter>
  </Style>

I can use a proxy binding to pass the datacontext to the MinorTickLineStyle style, but only in the UserControl itself, not an external resource dictionary.

I was hoping to do something like this:

<s:SciChartSurface>
      <SciChartSurface.XAxes ItemsSource="{Binding XAxes"} Style="{StaticResource AxisStyle}"/>
</s:SciChartSurface>

But XAxes does not have any properties I can access from XAML.

What would be a good way to apply a style from XAML and still have dynamic Axes.

Thank you,

  • You must to post comments
Best Answer
1
0

Hi Kewur,

This question seems to be a duplicate of this one: Template items of an AxisCollection possible and this one MVVM Multiple Axis Example.

Can you take a look and let me know if the solution(s) above help you?

Best regards,
Andrew

  • kewur
    Thank you Andrew, with a little edit to the YAxesBehaviour I got it working.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies