Pre loader

Turning ChartModifiers on and off using 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

0
0

Whenever possible I like to do simple UI related things such as changing the MouseWheelZoomModifier direction from Xaml.

My first attempt at this was to use DataTriggers on the MouseWheelZoomModifier bound to check boxes as such.

That did not work so I switched it to this. Radio buttons for mutually exclusive selection…

<StackPanel Orientation="Horizontal">
<RadioButton x:Name="xDirection"
Margin="5,3"
IsChecked="{Binding ElementName=mouseWheelZoomModifierX, Path=IsEnabled}"
Content="Zoom X Only" />

            &lt;RadioButton x:Name=&quot;yDirection&quot;
                      Margin=&quot;5,3&quot;
                      IsChecked=&quot;{Binding ElementName=mouseWheelZoomModifierY, Path=IsEnabled}&quot;
                      Content=&quot;Zoom Y Only&quot; /&gt;

            &lt;RadioButton x:Name=&quot;xyDirection&quot;
                      Margin=&quot;5,3&quot;
                      IsChecked=&quot;{Binding ElementName=mouseWheelZoomModifierXY, Path=IsEnabled}&quot;
                      Content=&quot;Zoom X&amp;amp;Y&quot; /&gt;

And three separate zoom modifiers…

<SciChart:MouseWheelZoomModifier x:Name="mouseWheelZoomModifierX"
IsEnabled="False"
XyDirection="XDirection" />
<SciChart:MouseWheelZoomModifier x:Name="mouseWheelZoomModifierY"
IsEnabled="False"
XyDirection="YDirection" />
<SciChart:MouseWheelZoomModifier x:Name="mouseWheelZoomModifierXY"
IsEnabled="True"
XyDirection="XYDirection" />

Am I missing something with the Triggers? If not this is working fine, it just seems like an odd way to do it…

  • You must to post comments
0
0

Hi Dwaldo,

You could do this in many ways. I think better approach to do this could be using ComboBox with XyDirection members and bind MouseWheelZoomModifier to its SelectedItem, or ToggleButton for it has three states, so you can write Converter and bind MouseWheelZoomModifier to IsChecked property, or you could modify your code in a such way:

            <CheckBox x:Name="xDirection"
                      Margin="5,3"
                      Checked="XDirection_Checked"
                      IsChecked="{Binding XyDirection, ElementName=mouseWheelZoomModifier, Mode=OneWayToSource, Converter={StaticResource directionConverter}, ConverterParameter=XDirection}"
                      Content="X Direction Only" />
            <CheckBox x:Name="yDirection"
                      Margin="5,3"
                      Checked="YDirection_Checked"
                      IsChecked="{Binding XyDirection, ElementName=mouseWheelZoomModifier, Mode=OneWayToSource, Converter={StaticResource directionConverter}, ConverterParameter=YDirection}"
                      Content="Y Direction Only" />
            <CheckBox x:Name="xyDirection"
                      Margin="5,3"
                      Checked="XYDirection_Checked"
                      IsChecked="{Binding XyDirection, ElementName=mouseWheelZoomModifier, Mode=OneWayToSource, Converter={StaticResource directionConverter}, ConverterParameter=XYDirection}"
                      Content="Both X and Y Direction" />

And one zoom modifier:

            <sciChart:SciChartSurface.ChartModifier>
                <sciChart:ModifierGroup>
                    <sciChart:MouseWheelZoomModifier x:Name="mouseWheelZoomModifier" />
                </sciChart:ModifierGroup>
            </sciChart:SciChartSurface.ChartModifier>

And the converter code:

    class DirectionConverter: IValueConverter
    {
        private XyDirection _selectedDirection;

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Enum.Parse(typeof(XyDirection), (string)parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if((bool)value)
            {
                _selectedDirection = (XyDirection)Enum.Parse(typeof(XyDirection), (string)parameter);
            }

            return _selectedDirection;
        }
    }

You should use only one MouseWheelZoomModifier in any case. So if you will have more questions, we will be glad to help!

Best regards,
Yuriy

  • 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