locked
editor extension RRS feed

  • Question

  • Hello,

    I'm new to learn Visual Studio extension. Recently, I'm think of create a information dialog or box to show some info of the file in VS. How do I create the dialog or the box? After thinking a lot, I guess the WPF user control may help. Is there any example?

    Thanks!

    Wednesday, July 9, 2014 12:57 PM

Answers

  • Hi,

    You can create a editor viewport adornment project, then add a WPF user control.

    More information, please refer to the tutorial.

    http://www.codeproject.com/Articles/55196/Code-InfoBox-Visual-Studio-Extension-VSX

    Right click on the project and add a new WPF user control. I have used a user control to simplify this. The user control actually contains one Expander which is made ExpandDirection = Left, which wraps around few TextBlock elements and another Expander which is made ExpandDirection = Down. The code looks like below (I removed unnecessary design elements from it to make it simpler) :

     <Expander ExpandDirection="Left" Style="{DynamicResource ExpanderStyle1}" 
               x:Name="expMain" >
      <StackPanel>
                    <TextBlock x:Name="txtNoLines" 
                               Text="No of Lines : {0}" 
                               Margin="25 25 25 0" 
                               FontSize="12" 
                               FontFamily="Verdana" 
                               FontWeight="Bold" 
                               Foreground="Yellow"></TextBlock>
                    <TextBlock x:Name="txtNoCharacters" 
                               Text="No of Characters : {0}" 
                               Margin="25 5 25 15" 
                               FontSize="12" 
                               FontFamily="Verdana" 
                               FontWeight="Bold" 
                               Foreground="Yellow"></TextBlock>
                    <Expander x:Name="expCodeInfo" ExpandDirection="Down" 
                                         Header="Code Information">
                        <StackPanel>
                            <TextBlock x:Name="txtClassInfo" 
                                       Margin="25 25 25 0" 
                                       FontSize="12" 
                                       FontFamily="Verdana" 
                                       FontWeight="Bold" 
                                       Foreground="LightYellow"/>
                            <Line
                                  Margin="0,4"
                                  SnapsToDevicePixels="True"
                                  Stroke="Gold"
                                  Stretch="Fill"
                                  X1="0" X2="1" 
                                  />
                            <TextBlock x:Name="txtFileSize"
                                       Margin="25 5 25 15" 
                                       FontSize="12" 
                                       FontFamily="Verdana" 
                                       FontWeight="Bold" 
                                       Foreground="AliceBlue"/>
                        </StackPanel>
                    </Expander>
                </StackPanel>
             </Expander>

    Thus you can see that the code looks very simple, with two Expanders, one for the Basic statistics and another for Enhanced statistics. I have used StackPanel to fix the layout of the TextBlocks.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Li_S Monday, July 14, 2014 1:07 AM
    Thursday, July 10, 2014 10:10 AM