1

It is possible to synchronize axes if you bind the VisibleRange of an Axis to a property of type IRange in the ViewModel. So if I have 2 charts I can bind them to the same IRange and they get synchronized. This works fine. Now I want to be able to activate or deactivate this behavior. I did something like this, but it is not working:

<s:SciChartSurface.YAxis>
    <s:NumericAxis>
        <s:NumericAxis.Style>
            <Style TargetType="s:NumericAxis">
                <Style.Triggers>
                  <DataTrigger Binding="{Binding SyncYaxes}" Value="True">
                      <Setter Property="VisibleRange" Value="{Binding 
                              SyncSharedYrange, Mode=TwoWay}"/>
                  </DataTrigger>
                  <DataTrigger Binding="{Binding SyncYaxes}" Value="False">
                      <Setter Property="VisibleRange" Value="{x:Null}"/>                        
                  </DataTrigger>
                </Style.Triggers>
            </Style>
        </s:NumericAxis.Style>
    </s:NumericAxis>
</s:SciChartSurface.YAxis>

After implemented these triggers, it stops working, it does not matter if the property SyncYaxes is true or false. If I set the binding without triggers, both axes are sync as expected, but I cannot stop this behavior if I want. What do you think ? How can this be done ?

Oscar Fonseca
  • 226
  • 2
  • 6
  • Some similar questions on conditional bindings in WPF. Try just the Datatrigger when value=true only? You can also try MultiBinding https://stackoverflow.com/a/28817452/303612 – Dr. Andrew Burnett-Thompson Jun 01 '18 at 11:14

1 Answers1

0

This did not work in XAML but I solved it in the ViewModel by binding each chart to a IRange and Then if they should be synchronized, every time one of the IRange changes, then the other gets updated by handling PropertyChanged (Only if SyncYAxes is true).

Oscar Fonseca
  • 226
  • 2
  • 6