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" />
<RadioButton x:Name="yDirection"
Margin="5,3"
IsChecked="{Binding ElementName=mouseWheelZoomModifierY, Path=IsEnabled}"
Content="Zoom Y Only" />
<RadioButton x:Name="xyDirection"
Margin="5,3"
IsChecked="{Binding ElementName=mouseWheelZoomModifierXY, Path=IsEnabled}"
Content="Zoom X&amp;Y" />
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…
- dwaldo asked 12 years ago
- You must login to post comments
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
- Yuriy Zadereckiy answered 12 years ago
- You must login to post comments
Please login first to submit.