Click here to Skip to main content
15,881,938 members
Articles / Desktop Programming / WPF

Improving WPF Mouse Wheel Processing

Rate me:
Please Sign up or sign in to vote.
4.91/5 (29 votes)
11 Jun 2016MIT16 min read 93.9K   3.8K   52  
How to quickly improve your WPF application to give your users a pleasant mouse wheel experience
<!-- DataContext : MouseWheelOptions -->
  
  <Window
  x:Class="Logitech.WpfMouseWheel.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:vm="clr-namespace:Logitech.WpfMouseWheel.ViewModels"
  xmlns:vw="clr-namespace:Logitech.WpfMouseWheel.Views"
  xmlns:i="clr-namespace:Logitech.Windows.Input;assembly=WpfMouseWheelLib"
  Title="WPF Mouse Wheel - Enhanced" Height="800" Width="800">

  <Window.Resources>
    <ObjectDataProvider x:Key="_options" ObjectType="{x:Type vm:MouseWheelOptions}" />
  </Window.Resources>

  <Window.DataContext>
    <Binding Source="{StaticResource _options}" />
  </Window.DataContext>

  <DockPanel Margin="4">

    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="1.5*"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
      </Grid.RowDefinitions>
      <!-- Splitter -->
      <GridSplitter Margin="2,0" Width="4" Grid.Column="1" Grid.RowSpan="2" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" Background="DarkSlateBlue"/>
      <!-- Options -->
      <Border Grid.Column="0" Background="DarkSlateBlue" Padding="4" CornerRadius="4">
        <TextBlock Text="Options" Foreground="White" HorizontalAlignment="Center" FontSize="16" FontWeight="DemiBold"/>
      </Border>
      <vw:MouseWheelOptionsView Margin="0,4,0,0" Grid.Row="1" Grid.Column="0" />
      <!-- Workspace -->
      <Border Grid.Column="2" Background="DarkSlateBlue" Padding="4" CornerRadius="4">
        <TextBlock Text="Demos" Foreground="White" HorizontalAlignment="Center" FontSize="16" FontWeight="DemiBold"/>
      </Border>
      <vw:WorkspaceView Margin="0,4,0,0" Grid.Row="1" Grid.Column="2"
        i:MouseWheel.Enhanced                  ="{Binding Enhanced}"
        i:MouseWheel.VScrollMode               ="{Binding ScrollOptions.Y.ScrollMode}"
        i:MouseWheel.HScrollMode               ="{Binding ScrollOptions.X.ScrollMode}"
        i:MouseWheel.VScrollSmoothing          ="{Binding ScrollOptions.Y.Smoothing}"
        i:MouseWheel.HScrollSmoothing          ="{Binding ScrollOptions.X.Smoothing}"
        i:MouseWheel.NestedVScroll             ="{Binding ScrollOptions.Y.NestedScroll}"
        i:MouseWheel.NestedHScroll             ="{Binding ScrollOptions.X.NestedScroll}"
        i:MouseWheel.PhysicalVScrollDebouncing ="{Binding ScrollOptions.Y.Physical.Debouncing}"
        i:MouseWheel.PhysicalHScrollDebouncing ="{Binding ScrollOptions.X.Physical.Debouncing}"
        i:MouseWheel.LogicalVScrollDebouncing  ="{Binding ScrollOptions.Y.Logical.Debouncing}"
        i:MouseWheel.LogicalHScrollDebouncing  ="{Binding ScrollOptions.X.Logical.Debouncing}"
        i:MouseWheel.PhysicalVScrollIncrement  ="{Binding ScrollOptions.Y.Physical.ScrollIncrementSelector.SelectedItem}"
        i:MouseWheel.PhysicalHScrollIncrement  ="{Binding ScrollOptions.X.Physical.ScrollIncrementSelector.SelectedItem}"
        i:MouseWheel.LogicalVScrollIncrement   ="{Binding ScrollOptions.Y.Logical.ScrollIncrementSelector.SelectedItem}"
        i:MouseWheel.LogicalHScrollIncrement   ="{Binding ScrollOptions.X.Logical.ScrollIncrementSelector.SelectedItem}"
        i:MouseWheel.ZoomSmoothing             ="{Binding ZoomOptions.Smoothing}"
        i:MouseWheel.ZoomDebouncing            ="{Binding ZoomOptions.Debouncing}"
        i:MouseWheel.NestedZoom                ="{Binding ZoomOptions.NestedZoom}"
      />
    </Grid>
  </DockPanel>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions