Overflow not working when hosted in Excel addin

5 posts, 0 answers
  1. Kahn
    Kahn avatar
    3 posts
    Member since:
    May 2013

    Posted 02 Feb Link to this post

    I'm using a RadToolBar in an Excel task pane. When the task pane is sized to move controls to the overflow, the overflow button will enable but clicking the overflow button will not display the controls. I've further narrowed the problem to when the WPF user control is converted to an INativeControlHandle and back before adding it to the task pane.

     

    I've built a sample project to demonstrate the problem. The sample also includes a regular WPF ToolBar which does not have the same problem. (remove the .jpg extension from the .zip file)

     

    Note that the same code hosted in a Word addin will function correctly as will a generic WinForms application.

     

    Any advice would be appreciated.

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 05 Feb Link to this post

    Hello Kahn,

    I can confirm the describe behavior also on my side. It comes from the fact that the Popup element that holds the toolbar's overflow lost focus right after it got it. This closes the popup. However, I will need time to further investigate your scenario. I will contact you in few days with more information on the matter.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kahn
    Kahn avatar
    3 posts
    Member since:
    May 2013

    Posted 05 Feb in reply to Martin Link to this post

    Thanks Martin.
  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 10 Feb Link to this post

    Hi Kahn,

    I spent some time to investigate the reported behavior and I can't tell that I am absolutely sure what is causing it. However, it seems that the Excel cells are getting the focus from the other elements. On the other hand the overflow of the toolbar is displayed in a Popup element which closes when lost its focus. Basically, clicking on the overflow button, the popup opens for a fragment of the second and then almost right away it closes because the focus is lost.

    This behavior can be observed also with native WPF components as ToggleButton and a Popup which IsOpen property is bound to the ToggleButton's IsChecked.
    <Grid>
        <ToggleButton x:Name="btn1" Content="Btn" Width="100" Height="100"/>
        <Popup StaysOpen="False" Focusable="False"
                       IsOpen="{Binding ElementName=btn1, Path=IsChecked}" AllowsTransparency="True">
            <TextBlock Text="Test" />
        </Popup>
    </Grid>
    You can also try to type into a WPF TextBox element - the focus will be sent to the selected Excel cell.

    As you mentioned this behavior appears only after the UserControl is converted to a contract and vice versa. Note that ContractToViewAdapter() won't return the same user control as the one passed in the ViewToContract() method, but an object of type HwndHost that wraps it and which might causing the issue. In addition the WPF Add-Ins Overview MSDN article talks about the removing isolation boundaries between the host application and the add-in when using the FrameworkElementAdapters class which might be related to the issue. I recommend you to check if there is anything similar discussed in StackOverflow or any other .NET community that concerns the FrameworkElementAdapters class and see if there is a solution for this behavior.

    As a workaround you can avoid using the FrameworkElementAdapters. Or you can use the ChildrenOfTypeExtensions.ChildrenOfType<T>() extension method to get the Popup of the RadToolBar control. Then set its StaysOpen property to True and close the popup manually, when necessary. You can control the visibility of the overflow popup using the toolbar's IsOverflowOpen property.

    I hope this information is useful.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Kahn
    Kahn avatar
    3 posts
    Member since:
    May 2013

    Posted 10 Feb in reply to Martin Link to this post

    Thanks for your help. It's much appreciated.

     

Back to Top
UI for WPF is Visual Studio 2017 Ready