-1

I have some xaml code like this:

<s:SciChartSurface>
    <s:SciChartSurface.XAxis>
        <s:NumericAxis Style="{Binding ..., Converter=...}" />
    </s:SciChartSurface.XAxis>
</s:SciChartSurface>

The x axis has a style that depends on a property. The converter selectes one of three different static resources defined somewhere in the xaml. Now the axis itself is polymorph, too, so I create it in the code behind:

<s:SciChartSurface>
    <s:SciChartSurface.XAxis>
        <Binding CreateAxis />
    </s:SciChartSurface.XAxis>
</s:SciChartSurface>

or

<s:SciChartSurface XAxis="{Binding CreateAxis}" />

But how can I apply the dynamic style to the object created in the code behind?

mm8
  • 163,881
  • 10
  • 57
  • 88
user829755
  • 1,489
  • 13
  • 27
  • so why is that a downvote? I spent a whole day trying to get this working and searching for an answer before I asked. It just took me some time to verify the solution – user829755 Jun 13 '17 at 15:19

1 Answers1

0

Your question is a bit unclear since you haven't posted any code-behind code at all, but I believe you want to be able to do something like this:

var axis = new SciChart.Charting.Visuals.Axes.NumericAxis();
axis.SetBinding(SciChart.Charting.Visuals.Axes.NumericAxis.StyleProperty, new System.Windows.Data.Binding("Path") { Converter = new YourConverterClass });
ss.XAxis = axis;

Give the SciChartSurface element an x:Name in your XAML markup and then set its XAxis property to a NumericAxis object that you create programmatically:

<s:SciChartSurface x:Name="ss">
mm8
  • 163,881
  • 10
  • 57
  • 88
  • not exactly. instead of the 2nd line I want to say axis.Style = ..., the ... would then replace the converter (a converter is a hack around limitations of xaml), the 3rd line would still be in the xaml. the link to the similar problem shows that I can easily access the styles defined in the xaml – user829755 Jun 13 '17 at 15:00
  • Where is your actual style defined then? Because you are *binding* the Style property to a source property in the sample XAML you have posted. – mm8 Jun 13 '17 at 15:01