none
Word Add-in CustomTaskPane Scroll Problem RRS feed

  • Question

  • Hi!

    I'm working in an Add-in for MS Word, so in order to develop a more advanced user interface I decided to use WPF.

    I need to display a list of tags, so I'm using a ScrollViewer with an ItemsControl in it. This is my code:

       <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="2">
                <ItemsControl Grid.Column="1"                         
                  Grid.Row="1"
                  Width="Auto"
                  Height="Auto"
                  ItemsSource="{Binding Source={StaticResource tags}}"
                  ItemTemplate="{StaticResource tagTemplate}" 
                  ScrollViewer.CanContentScroll="True">                       
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate >
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </ScrollViewer>
    

    The problem is the mouse wheel scrolling is not working. Instead of scrolling the list, the scroll event is attached to the word document. When I scroll over the list it doesn't work, but if I click and scroll it works once, and then I need to click again. I think this is a focus problem, because the list is constatly loosing focus.

    Thanks in adavance for your suggestions.

    Thursday, January 26, 2012 10:57 AM

All replies

  • Hi,

    I think I know what's is the problem wich is causing to lose focus. I have one MouseEnter and MouseLeave events on the items of ItemsControl (are defined in the ItemTemplate). 

    On MouseEnter and MouseLeave I have the following code:

    WPFContent.MyControlEventArgs ee = (WPFContent.MyControlEventArgs)e;
    Range range = this.addin.Application.ActiveDocument.Content
    Find find = range.Find;
    find.Text = ee.TagElement.TagText;
    find.MatchWholeWord = true;
    find.Execute();
    
    while (find.Found)
    {
      range.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdYellow;  find.Execute();
    }
    

    so, basically the Find operation is causing to loose the Focus. 

    My question now is if it's possible to programmatically pass the focus to the ScrollViewer again.

    Thanks in advance!

    Friday, January 27, 2012 10:28 AM
  • Hi doaidag,

     

    Thanks for posting in the MSDN Forum.

     

    I think the “focus” you mentioned in the post means a range of the current document is it right?

     

    It’s based on my experience you need use Find.Found method again to back to the original position. If I have misunderstood anything, please feel free to let me know.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 30, 2012 5:14 AM
    Moderator
  • Hi Tom! Thanks for your answer!

    By focus I mean the currently active component. Imagine I'm scrolling the list in my addin, like I said. When the mouse events that I mentioned in the previous posts are fired, the scroll action starts scrolling the document and not the list.

    I treid to use the Find.Found method again but without success...

    Any oder ideia?

    Thanks very much for the attention!

     

    Greg

    Friday, February 3, 2012 5:41 PM