How to disable scrolling in ScrollViewer while Ctrl is pressed

Posted by zunyite on Stack Overflow See other posts from Stack Overflow or by zunyite
Published on 2010-06-07T18:52:19Z Indexed on 2010/06/14 11:22 UTC
Read the original article Hit count: 1048

Filed under:
|

I'd like to implement zoom function while Ctrl key is pressed. But the MouseWheel event is not trigger while the mouse is over the ScrollView.

Is there any way to do it?

ps:SilverLight 4.0

<UserControl x:Class="SilverlightApplication11.MainPage"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         d:DesignHeight="300"
         d:DesignWidth="400">

<Grid x:Name="LayoutRoot"
      Background="White">
    <ScrollViewer Background="Gray"
                  MouseWheel="ScrollViewer_MouseWheel"
                  x:Name="scrollViewer">
        <Rectangle Width="200"
                   Height="2000"
                   MouseWheel="ScrollViewer_MouseWheel"
                   Fill="AliceBlue" />
    </ScrollViewer>
</Grid>

    private void ScrollViewer_MouseWheel(object sender, MouseWheelEventArgs e)
    {
        if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
        {
            zoom+=0.1;
            e.Handled = true;
        }
    }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Silverlight