@@ -42,13 +42,16 @@ private void FillToBounds(object sender, ExecutedRoutedEventArgs e)
42
42
43
43
#endregion
44
44
45
- #region Fit Command
45
+ #region ResetZoom Command
46
46
47
- public static RoutedUICommand Fit = new RoutedUICommand ( "Fit Content within Bounds" , "FitToBounds" , typeof ( ZoomControl ) ) ;
48
-
49
- private void FitToBounds ( object sender , ExecutedRoutedEventArgs e )
47
+ public static RoutedUICommand ResetZoom = new RoutedUICommand ( "Reset zoom" , "ResetZoom" , typeof ( ZoomControl ) ) ;
48
+ /// <summary>
49
+ /// Executes when ResetZoom command is fired and resets the Zoom value to default one. Override to reset to custom zoom value.
50
+ /// Default Zoom value is 1.
51
+ /// </summary>
52
+ protected virtual void ExecuteResetZoom ( object sender , ExecutedRoutedEventArgs e )
50
53
{
51
-
54
+ Zoom = 1d ;
52
55
}
53
56
54
57
#endregion
@@ -1051,8 +1054,12 @@ public ZoomControlModes Mode
1051
1054
set { SetValue ( ModeProperty , value ) ; }
1052
1055
}
1053
1056
1054
- protected RoutedUICommand CommandZoomIn = new RoutedUICommand ( "Zoom In" , "ZoomIn" , typeof ( ZoomControl ) ) ;
1055
- protected RoutedUICommand CommandZoomOut = new RoutedUICommand ( "Zoom Out" , "ZoomOut" , typeof ( ZoomControl ) ) ;
1057
+ public RoutedUICommand CommandZoomIn = new RoutedUICommand ( "Zoom In" , "ZoomIn" , typeof ( ZoomControl ) ) ;
1058
+ public RoutedUICommand CommandZoomOut = new RoutedUICommand ( "Zoom Out" , "ZoomOut" , typeof ( ZoomControl ) ) ;
1059
+ public RoutedUICommand CommandPanLeft = new RoutedUICommand ( "Pan Left" , "PanLeft" , typeof ( ZoomControl ) ) ;
1060
+ public RoutedUICommand CommandPanRight = new RoutedUICommand ( "Pan Right" , "PanRight" , typeof ( ZoomControl ) ) ;
1061
+ public RoutedUICommand CommandPanTop = new RoutedUICommand ( "Pan Top" , "PanTop" , typeof ( ZoomControl ) ) ;
1062
+ public RoutedUICommand CommandPanBottom = new RoutedUICommand ( "Pan Bottom" , "PanBottom" , typeof ( ZoomControl ) ) ;
1056
1063
1057
1064
#endregion
1058
1065
@@ -1061,6 +1068,11 @@ protected virtual void HookBeforeZoomChanging() { }
1061
1068
protected virtual void HookAfterZoomChanging ( ) { }
1062
1069
#endregion
1063
1070
1071
+ /// <summary>
1072
+ /// Gets or sets manual pan sensivity in points when using keys to pan zoomed content. Default value is 10.
1073
+ /// </summary>
1074
+ public double ManualPanSensivity { get ; set ; } = 10d ;
1075
+
1064
1076
static ZoomControl ( )
1065
1077
{
1066
1078
DefaultStyleKeyProperty . OverrideMetadata ( typeof ( ZoomControl ) , new FrameworkPropertyMetadata ( typeof ( ZoomControl ) ) ) ;
@@ -1083,27 +1095,44 @@ public ZoomControl()
1083
1095
BindCommand ( Refocus , RefocusView , CanRefocusView ) ;
1084
1096
BindCommand ( Center , CenterContent ) ;
1085
1097
BindCommand ( Fill , FillToBounds ) ;
1086
- BindCommand ( Fit , FitToBounds ) ;
1087
-
1088
- BindKey ( CommandZoomIn , Key . Up , ModifierKeys . Control ,
1089
- ( sender , args ) => MouseWheelAction ( 120 , OrigoPosition ) ) ;
1090
- BindKey ( CommandZoomOut , Key . Down , ModifierKeys . Control ,
1091
- ( sender , args ) => MouseWheelAction ( - 120 , OrigoPosition ) ) ;
1092
-
1098
+ BindCommand ( ResetZoom , ExecuteResetZoom ) ;
1099
+ BindCommand ( CommandZoomIn , ( sender , args ) => MouseWheelAction ( ZoomSensitivity , OrigoPosition ) ) ;
1100
+ BindCommand ( CommandZoomOut , ( sender , args ) => MouseWheelAction ( - ZoomSensitivity , OrigoPosition ) ) ;
1101
+ BindCommand ( CommandPanLeft , ( sender , args ) => PanAction ( new Vector ( TranslateX , TranslateY ) , new Vector ( ManualPanSensivity , 0 ) ) ) ;
1102
+ BindCommand ( CommandPanRight , ( sender , args ) => PanAction ( new Vector ( TranslateX , TranslateY ) , new Vector ( - ManualPanSensivity , 0 ) ) ) ;
1103
+ BindCommand ( CommandPanTop , ( sender , args ) => PanAction ( new Vector ( TranslateX , TranslateY ) , new Vector ( 0 , ManualPanSensivity ) ) ) ;
1104
+ BindCommand ( CommandPanBottom , ( sender , args ) => PanAction ( new Vector ( TranslateX , TranslateY ) , new Vector ( 0 , - ManualPanSensivity ) ) ) ;
1105
+ BindKey ( CommandPanLeft , Key . Left , ModifierKeys . None ) ;
1106
+ BindKey ( CommandPanRight , Key . Right , ModifierKeys . None ) ;
1107
+ BindKey ( CommandPanTop , Key . Up , ModifierKeys . None ) ;
1108
+ BindKey ( CommandPanBottom , Key . Down , ModifierKeys . None ) ;
1109
+ BindKey ( CommandZoomIn , Key . Up , ModifierKeys . Control ) ;
1110
+ BindKey ( CommandZoomOut , Key . Down , ModifierKeys . Control ) ;
1093
1111
}
1094
1112
}
1095
1113
1096
-
1097
1114
protected void BindCommand ( RoutedUICommand command , ExecutedRoutedEventHandler execute , CanExecuteRoutedEventHandler canExecute = null )
1098
1115
{
1099
1116
var binding = new CommandBinding ( command , execute , canExecute ) ;
1100
1117
CommandBindings . Add ( binding ) ;
1101
1118
}
1102
1119
1103
- protected void BindKey ( RoutedUICommand command , Key key , ModifierKeys modifier , ExecutedRoutedEventHandler execute )
1120
+ /// <summary>
1121
+ /// Resets all key bindings for the control
1122
+ /// </summary>
1123
+ public void ResetKeyBindings ( )
1124
+ {
1125
+ InputBindings . Clear ( ) ;
1126
+ }
1127
+
1128
+ /// <summary>
1129
+ /// Binds specified key to command
1130
+ /// </summary>
1131
+ /// <param name="command">Command to execute on key press</param>
1132
+ /// <param name="key">Key</param>
1133
+ /// <param name="modifier">Key modifier</param>
1134
+ public void BindKey ( RoutedUICommand command , Key key , ModifierKeys modifier )
1104
1135
{
1105
- var binding = new CommandBinding ( command , execute ) ;
1106
- CommandBindings . Add ( binding ) ;
1107
1136
InputBindings . Add ( new KeyBinding ( command , key , modifier ) ) ;
1108
1137
}
1109
1138
@@ -1173,9 +1202,9 @@ private void MouseWheelAction(MouseWheelEventArgs e)
1173
1202
/// <summary>
1174
1203
/// Defines action on mousewheel
1175
1204
/// </summary>
1176
- /// <param name="delta"></param>
1177
- /// <param name="mousePosition"></param>
1178
- protected virtual void MouseWheelAction ( int delta , Point mousePosition )
1205
+ /// <param name="delta">Delta from mousewheel args </param>
1206
+ /// <param name="mousePosition">Mouse position </param>
1207
+ protected virtual void MouseWheelAction ( double delta , Point mousePosition )
1179
1208
{
1180
1209
var origoPosition = OrigoPosition ;
1181
1210
DoZoom (
@@ -1224,6 +1253,14 @@ private void ZoomControl_MouseUp(object sender, MouseButtonEventArgs e)
1224
1253
ReleaseMouseCapture ( ) ;
1225
1254
}
1226
1255
1256
+ protected virtual void PanAction ( Vector initialPoint , Vector diff )
1257
+ {
1258
+ var translate = initialPoint + diff ;
1259
+ TranslateX = translate . X ;
1260
+ TranslateY = translate . Y ;
1261
+ UpdateViewport ( ) ;
1262
+ }
1263
+
1227
1264
private void ZoomControl_PreviewMouseMove ( object sender , MouseEventArgs e )
1228
1265
{
1229
1266
if ( _clickTrack )
@@ -1239,10 +1276,7 @@ private void ZoomControl_PreviewMouseMove(object sender, MouseEventArgs e)
1239
1276
case ZoomViewModifierMode . None :
1240
1277
return ;
1241
1278
case ZoomViewModifierMode . Pan :
1242
- var translate = _startTranslate + ( e . GetPosition ( this ) - _mouseDownPos ) ;
1243
- TranslateX = translate . X ;
1244
- TranslateY = translate . Y ;
1245
- UpdateViewport ( ) ;
1279
+ PanAction ( _startTranslate , e . GetPosition ( this ) - _mouseDownPos ) ;
1246
1280
break ;
1247
1281
case ZoomViewModifierMode . ZoomIn :
1248
1282
break ;
@@ -1404,18 +1438,6 @@ void ZoomCompleted(object sender, EventArgs e)
1404
1438
1405
1439
#endregion
1406
1440
1407
- /// <summary>
1408
- /// Zoom to rectangle area (MAY BE DEPRECATED). Use ZoomToContent method instead.
1409
- /// </summary>
1410
- /// <param name="rect"></param>
1411
- /// <param name="setDelta"></param>
1412
- public void ZoomTo ( Rect rect , bool setDelta = false )
1413
- {
1414
- ZoomToInternal ( rect , setDelta ) ;
1415
- UpdateViewFinderDisplayContentBounds ( ) ;
1416
- UpdateViewport ( ) ;
1417
- }
1418
-
1419
1441
/// <summary>
1420
1442
/// Zoom to rectangle area of the content
1421
1443
/// </summary>
0 commit comments