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,
- kewur asked 9 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 9 years ago
-
Thank you Andrew, with a little edit to the YAxesBehaviour I got it working.
- You must login to post comments
Please login first to submit.