Click here to Skip to main content
15,498,859 members
Articles / Desktop Programming / WPF
Posted 8 Feb 2010


51 bookmarked

ZoomSliderVSX - Visual Studio Extension (VSX) 2010

Rate me:
Please Sign up or sign in to vote.
4.95/5 (48 votes)
8 Feb 2010CPOL5 min read
Scrollable Zooming Extension for VS 2010

Table of Contents


Developing Visual Studio 2010 Extension is very much easy and full of fun. I have developed one small extension for VS 2010 called "ZoomSliderVSX". ZoomSliderVSX will provide you a sliding Zooming facility to zoom your source code, where minimum zoom level is 20% and maximum is 400%. Though Visual Studio 2010 has an inbuilt dropdown to set the zoom level for VS Source editor still I found that the scrolling features is missing which is one of the most common features in most of the Microsoft Products like Microsoft-Word, Excel. So I have implemented this small add-in for Visual Studio 2010. Hope you will enjoy it. Please provide your valuable feedback and suggestions to improve this control.

Image 2

Figure: ZoomSliderVSX UI

Prerequisite for Extension Development

For developing Visual Studio 2010 Extension, we need to have the following installed in our system:

  1. Visual Studio 2010 Beta 2
  2. Visual Studio 2010 Beta 2 SDK

Developing ZoomSliderVSX

Before we start with implementation, please make sure that all the required things are installed that are mentioned in the prerequisite section.

Extension Template Selection

After installing VS 2010 SDK, we will have different types of Extension Templates and based on our requirement, we have to select proper extension template. For ZoomSlider, I have used "Editor Margin" Template. If you want to learn more about what are the uses of other extension templates, please have a look into this.

To start up, Open Visual Studio 2010 IDE. Goto Start > New > Project. Select "Extensibility" from Left side template section. Then select "Editor Margin" Extension.

Image 3

Figure: Select Extension Template

Default Solution Structure

After selecting template, give the project name as "ZoomSliderVSX" and click on "Ok". This will create one Sample VS Addin control of Editor margin type. Below is the default file structure for the "Editor Margin" type solution.

Image 4

Figure: Default Solution Structure

As my control name is "ZoomSlider", I have renamed both the CS files to "ZoomSlider.cs" and "ZoomSliderFactory.cs". I have explained the use of both the files in the "Code" section. Now we are already set for starting our development, but one thing is remaining, adding the WPF user control. This is the heart of this extension. So, let’s add one WPF user control named "SliderControl.xaml".

Adding WPF User Control

To add user control in the application, right click on the project > Add > New Item

Image 5

Figure: Adding New Item

Now Select "WPF Control" from the list of items.

Image 6

Figure: Adding New WPF Control

Name the control as "SlideControl.xaml" and click on OK. Now, below is the final solution structure for "ZoomSliderVSX".

Final Solution Structure

So currently, we are having two CS files and one WPF control for the whole extension.

Image 7

Figure: Final solution structure for development

So, let's have a look into the code.

Using Code

In this application, we have three main code files: ZoomSlider.cs, ZoomSliderFactory.cs and SliderControl.XML.

The ZoomControl class has been created to handle appropriate methods when the actual execution takes place within the extension. This class actually creates an object of the WPF User control, and places the control in Editor Margin. ZoomSlider constructor is used to place the control into margin and handle the LayoutChanged event when required.

// The IWpfTextView that our margin will be attached to.
private IWpfTextView _textView;

// The name of the margin
public const string MarginName = "ZoomSlideBar";

// A flag stating whether this margin has been disposed
private bool _isDisposed = false;

//Slider WPF User Control 
private SliderControl _slider = null;

public ZoomSlider(IWpfTextView textView)
    // Set the IWpfTextView
    _textView = textView;

    // Establish the background of the margin.
    this.Height = 30;
    this.ClipToBounds = true;
    this.Background = new SolidColorBrush(Color.FromArgb(60, 41,57, 85));
    //Set Direction of Control
    this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
    //Add Event handler for for LayoutChanges Event
    _textView.LayoutChanged += this.OnLayoutChanged;
    //Create New instance for WPF Slider Control
    _slider = new SliderControl(_textView);

    //Add Control

ZoomSliderFactory class creates the object of ZoomSlider and returns it. In this class, we can also set property like order, margin, etc.

namespace ZoomSliderVSX
    #region ZoomSliderVSX Factory
    //Ensure that the margin occurs below the horizontal scrollbar
    [Order(After = PredefinedMarginNames.HorizontalScrollBar)]
    //Set the container to the bottom of the editor window
    //Do this for all content types
    internal sealed class ZoomSliderFactory : IWpfTextViewMarginProvider
        public IWpfTextViewMargin CreateMargin
	(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin)
            return new ZoomSlider(textViewHost.TextView);

Now, check the code for the actual WPF control. This is very much simple where I have used two buttons and one Slider control.

 <StackPanel Orientation="Horizontal" Height="25">
    <Label Name="ZoomValue"

    <Button Name="ZoomMinus"
   <Slider Name="Zoomer"
                <GradientStop Color="#FFBE2C00" Offset="0" />
                <GradientStop Color="#FF9DB7B7" Offset="1" />
    <Button Name="ZoomPlus"


Now all the events for button and slider control are handled in the xaml.cs file. Code for handling the slider value and setting the zoom level of textview is as below. We need to just increase and decrease the value of slider and based on that, we have set the TextView Zoom Level. Here SliderControl(IWpfTextView view) gets initialized from zoomslider class and Slider control receives the reference of WPFTextView.

namespace ZoomSliderVSX
    /// <summary>
    /// Interaction logic for Slider.xaml
    /// </summary>
    public partial class SliderControl : UserControl
        //Initilize TextView
        IWpfTextView _view = null;
        public SliderControl()

        /// <summary>
        /// Initilize Slider  Control
        /// </summary>
        /// <param name=""view"">
        public SliderControl(IWpfTextView view)
            this._view = view;
        /// <summary>
        /// Click on Plus Button
        /// </summary>
        /// <param name=""sender"">
        /// <param name=""e"">
        private void ZoomPlus_Click(object sender, RoutedEventArgs e)
            Zoomer.Value = Zoomer.Value + 10;
            _view.ZoomLevel = Zoomer.Value;
            ZoomValue.Content = "%" + Zoomer.Value;

        /// <summary>
        /// Click on Minus Button
        /// </summary>
        /// <param name=""sender"">
        /// <param name=""e"">
        private void ZoomMinus_Click(object sender, RoutedEventArgs e)
            Zoomer.Value = Zoomer.Value - 10;
            _view.ZoomLevel = Zoomer.Value;
            ZoomValue.Content = "%" + Zoomer.Value;

        /// <summary>
        /// On Change of Slider Value
        /// </summary>
        /// <param name=""sender"">
        /// <param name=""e"">
        private void Zoomer_ValueChanged(object sender, 
			RoutedPropertyChangedEventArgs<double> e)
            ZoomValue.Content = "%" + Zoomer.Value ;
            //Set the Zoom Level
            _view.ZoomLevel = Zoomer.Value;

        /// <summary>
        /// Update Slider on Layout Changed
        /// </summary>
        public void UpdateSlider()
            //Check if need be update the slider 
            if (Zoomer.Value != _view.ZoomLevel)
                //Set the Zoom Value to Content and Slider
                ZoomValue.Content = "%" + _view.ZoomLevel;
                Zoomer.Value = _view.ZoomLevel;

Here I have also handled the layout changed event for Visual Studio editor. As I have already mentioned, VS 2010 has inbuilt Zooming dropdown to zoom the text, so I have integrated those changes with the ZoomSlider. In ZoomSlider.Cs file, inside ZoomSlider() constructor I have handled the event for layout change event.

private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
    if (_slider != null)
    //Call Update method of SliderControl

So, on layout change, it will call the UpdateSlider() method of my Slider usercontrol, which will automatically set the value of Slider and label based on the changes in dropdown list.

public void UpdateSlider()
    //Check if need be update the slider 
    if (Zoomer.Value != _view.ZoomLevel)
        //Set the Zoom Value to Content and Slider
        ZoomValue.Content = "%" + _view.ZoomLevel;
        Zoomer.Value = _view.ZoomLevel;

We are now done with our development. Now, just build the application and run.

Run and Test Application

Whenever we run any extention control to test, Visual Studio will create one "Experimental Instance" where you can see your extension is on placed inside the VS IDE. This instance can also be used for debugging your control.

Image 8

Figure: Test Application in VS Experimental Instance

Installation of ZoomSliderVSX

This is very easy. First of all, we need to run the .vsix file to setup the addin within Visual Studio IDE. Then we have to open "ExtentionManager" from Tool > Extension Manager to manage the extension where we can easily "Install", "Uninstall" or "Disabled" any extension.

Image 9

Figure: Installing and Uninstalling ZoomSliderVSX

How to Use ZoomSliderVSX

Using Zoom Slider is very similar to using any zooming control. This is similar to all other Microsoft products like Microsoft-Office, Microsoft-Excel zooming control. Use Scroll to Zoom-in or Zoom-Out. You can use "+" and "-" button to achieve the same.

Image 10

Figure: Using ZoomSlider

If you change the value of Dropdown list zoom level, that will also be reflected in ZoomSlider as these are integrated with each other.

Publishing Extension - MSDN Visual Studio Gallery

I have published the extension in MSDN Visual Studio Gallery. This is also very simple. You just need to upload the VSIX file. Here is my Extension in MSDN Visual Studio Library.


Developing an extension for VS 2010 is very easy and lots of fun. This is my first extension for VS 2010. Though this is very simple, I have enjoyed a lot. I have published the same in MSDN Visual Studio Gallery also. Please provide your feedback and suggestions.


  • Initial draft: 9th Feb - 2010


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Technical Lead
India India
.NET Consultant | Former Microsoft MVP - ASP.NET | CodeProject MVP, Mentor, Insiders| Technology Evangelist | Author | Speaker | Geek | Blogger | Husband

Blog :
Web Site :
Twitter : @AbhijitJana
My Kinect Book : Kinect for Windows SDK Programming Guide

Comments and Discussions

QuestionGreat Article Pin
ArsenMkrt4-Jun-12 0:19
MemberArsenMkrt4-Jun-12 0:19 
GeneralMy vote of 5 Pin
ashutosh k. shukla18-Jan-12 3:34
Memberashutosh k. shukla18-Jan-12 3:34 
QuestionMy vote of 5 Pin
Filip D'haene8-Sep-11 7:21
MemberFilip D'haene8-Sep-11 7:21 
GeneralMy vote of 5 Pin
Saraf Talukder31-Aug-11 4:02
MemberSaraf Talukder31-Aug-11 4:02 
GeneralMy vote of 5 Pin
Sandesh M Patil3-Mar-11 6:57
MemberSandesh M Patil3-Mar-11 6:57 
GeneralNice Article! Pin
Your Display Name Here28-Oct-10 11:25
MemberYour Display Name Here28-Oct-10 11:25 
GeneralRe: Nice Article! Pin
Abhijit Jana30-Oct-10 12:49
professionalAbhijit Jana30-Oct-10 12:49 
GeneralCongrats Pin
Blue_Boy17-Aug-10 1:37
MemberBlue_Boy17-Aug-10 1:37 
AnswerRe: Congrats Pin
Abhijit Jana27-Aug-10 9:08
professionalAbhijit Jana27-Aug-10 9:08 
GeneralCongrats for the Grand Prize - Sony VAIO Pin
Kunal Chowdhury «IN»10-May-10 8:57
professionalKunal Chowdhury «IN»10-May-10 8:57 
GeneralRe: Congrats for the Grand Prize - Sony VAIO Pin
Abhijit Jana10-May-10 9:22
professionalAbhijit Jana10-May-10 9:22 
GeneralRe: Congrats for the Grand Prize - Sony VAIO Pin
Rajesh R Subramanian10-May-10 9:38
professionalRajesh R Subramanian10-May-10 9:38 
GeneralRe: Congrats for the Grand Prize - Sony VAIO Pin
Abhijit Jana10-May-10 10:16
professionalAbhijit Jana10-May-10 10:16 
GeneralRe: Congrats for the Grand Prize - Sony VAIO Pin
Dr.Luiji10-May-10 12:54
professionalDr.Luiji10-May-10 12:54 
GeneralRe: Congrats for the Grand Prize - Sony VAIO Pin
Abhijit Jana10-May-10 19:10
professionalAbhijit Jana10-May-10 19:10 
GeneralNicely done Pin
Muhammad Gouda31-Mar-10 12:45
MemberMuhammad Gouda31-Mar-10 12:45 
GeneralRe: Nicely done Pin
Abhijit Jana31-Mar-10 21:34
professionalAbhijit Jana31-Mar-10 21:34 
GeneralRe: Nicely done Pin
Muhammad Gouda1-Apr-10 11:25
MemberMuhammad Gouda1-Apr-10 11:25 
GeneralGreat article & Congrats! Pin
Sandeep Mewara15-Mar-10 22:34
mveSandeep Mewara15-Mar-10 22:34 
GeneralRe: Great article & Congrats! Pin
Abhijit Jana15-Mar-10 22:41
professionalAbhijit Jana15-Mar-10 22:41 
GeneralCongratulations, Abhijit Pin
Marcelo Ricardo de Oliveira12-Mar-10 5:39
mvaMarcelo Ricardo de Oliveira12-Mar-10 5:39 
GeneralRe: Congratulations, Abhijit Pin
Abhijit Jana12-Mar-10 5:58
professionalAbhijit Jana12-Mar-10 5:58 
GeneralExcellent Pin
Katka Vaughan11-Mar-10 4:18
MemberKatka Vaughan11-Mar-10 4:18 
GeneralRe: Excellent Pin
Abhijit Jana11-Mar-10 4:24
professionalAbhijit Jana11-Mar-10 4:24 
GeneralExtremelly well done Pin
Ravenet9-Mar-10 18:28
MemberRavenet9-Mar-10 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.