Search code examples
c#wpfxamlwpf-extended-toolkit

Change keys Extended WPF Toolkit Zoombox


I'm using the Extended WPF Toolkit's Zoombox. Right now, Ctrl + drag and drop is changing the position, and alt + Scroll is changing the zoom. Logically I'd rather have this turned around since in most software Ctrl+Scroll is used for zooming. How do I change these keys? I played around with DragModifiers and RelativeZoomModifiers property but can't get it to work.

I tried the following:

<xctk:Zoombox Margin="20" ClipToBounds="False" HorizontalAlignment="Stretch" Name="CanvasZoombox" VerticalAlignment="Stretch" Scale="1" AutoWrapContentWithViewbox="False">
    <xctk:Zoombox.ZoomModifiers>
        <xctk:KeyModifier>LeftCtrl</xctk:KeyModifier>
    </xctk:Zoombox.ZoomModifiers>
    <xctk:Zoombox.RelativeZoomModifiers>
        <xctk:KeyModifier>LeftCtrl</xctk:KeyModifier>
    </xctk:Zoombox.RelativeZoomModifiers>

    <Viewbox Stretch="Uniform" Name="CanvasViewbox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" OpacityMask="White">
        <Canvas  Name="LabelCanvas" Background="#FFC3C3C3"/>
    </Viewbox>
</xctk:Zoombox>

This doesn't change anything unfortunately


Solution

  • Since you dont stated, why you didnt got it to work, here an Code-Behind-Example:

      var zoomKeys = new KeyModifierCollection();
      zoomKeys.Add(KeyModifier.Ctrl);
      zoomKeys.Add(KeyModifier.Exact);
      var dragKeys = new KeyModifierCollection();
      dragKeys.Add(KeyModifier.Alt);
      dragKeys.Add(KeyModifier.Exact);
      this.zoombox.ZoomModifiers = zoomKeys;
      this.zoombox.DragModifiers = dragKeys;
    

    Since these Modifiers are all DependencyProperties, you can also bind them in the MVVM-fashioned way.

    Update

    The XAML-way

    <xctk:Zoombox.ZoomModifiers>
          <xctk:KeyModifierCollection>
                <xctk:KeyModifier>Ctrl</xctk:KeyModifier>
                <xctk:KeyModifier>Exact</xctk:KeyModifier>
           </xctk:KeyModifierCollection>
     </xctk:Zoombox.ZoomModifiers>
     <xctk:Zoombox.DragModifiers>
           <xctk:KeyModifierCollection>
                 <xctk:KeyModifier>Alt</xctk:KeyModifier>
                 <xctk:KeyModifier>Exact</xctk:KeyModifier>
           </xctk:KeyModifierCollection>
     </xctk:Zoombox.DragModifiers>
    

    The trick is to wrap the KeyModifier in its suiting collection KeyModifierCollection