tags:

views:

723

answers:

3

I have a strange bug with WPF Interop and an Excel Addin. I'm using .Net 3.5 SP1.

I'm using Add-in Express to create a Custom Task Pane for Excel 2003. Within that taskpane I'm using ElementHost to host a WPF UserControl. The UserControl simply contains a Grid with a TextBox and ComboBox. My problem is that whilst everything displays properly, the ComboBox won't stay dropped-down unless I hold the mouse down over the down-arrow.

I don't believe this is necessarily related to Add-in Express because I've had a similar problem when I tried displaying a WPF window modelessly in Excel.

A second problem is that the ComboBox seems reluctant to give up focus. If I click it, the text area goes grey to indicate that it has focus, but I can't move focus anywhere else in the window. The only way to wrest focus away is to move the mousewheel.

Anybody else had a similar problem, and managed to fix it?

A: 

Hi,

I'm not sure if it'll work but the ComboBox has got a StaysOpenOnEdit property which you can set to true.

You might have to set IsEditable to true (will have to try), after which you can still set IsReadyOnly to true if you do not want them to actually edit the item.

Now, since you're doing this inside Office, I should note I heard one of the WPF developers talking about a demo he gave doing something similar to what you are doing and he had the same problem... which he only noticed during the presentation :p

But that was a long time ago, and with all the updates to WPF since then, this might no longer be the case.

So try the properties first.

TimothyP
Timothy, I'm pretty sure that that only applies when you try typing in the text part of the combo: I'm not doing that.
Samuel Jack
No idea m8, haven't had the time to try this myself
TimothyP
A: 

Add-in Express looked into this for me, and it turns out to have something to do with the Window style of the Task Pane that gets added to Excel. If you turn off the WS_CHILD flag in the Windows CreateParams then Combo Boxes and other popups work as expected.

They gave me this snippet of code to add to my ADXExcelTaskPane:

    private const uint WS_CHILD = 0x40000000;
    private const uint WS_CLIPCHILDREN = 0x02000000;
    private const uint WS_CLIPSIBLINGS = 0x04000000;

    private CreateParams fCreateParams = new CreateParams();
    protected override CreateParams CreateParams
    {
        get
        {
            fCreateParams = base.CreateParams;
            if (!DesignMode)
            {
                fCreateParams.Style = (int)(WS_CLIPCHILDREN | WS_CLIPSIBLINGS); //| WS_CHILD
            }
            return fCreateParams;
        }
    }
Samuel Jack
A: 

Hi, for me this looks similar to my problem, but I don't use "add-in express", but only the tools available within Visual Studio 2008. Our situation is: ContextMenu does not stay open, if the WPF-window is modeless. It works properly with a modal window.

Has anyone an idea how to have it remain open in modeless window, too? Maybe something similar to the solution described by Samuel Jack?

Or is this fixed with some newer version? (I use Excel 2003, .NET3.5 SP1) Thanks for any hints Walter

Walter Rohrer