Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WPF Popup - Form Moved
Message
De
02/03/2008 05:27:22
 
 
À
01/03/2008 14:03:45
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01295934
Message ID:
01298028
Vues:
45
This message has been marked as a message which has helped to the initial question of the thread.
>>>The above code certainly seems a bit of a kludge - but if you're happy to have the popup close then just 'TogglePopups(false);' in the event handler should do it? Of course you'd need the same behaviour for any resizing as well.
>
>What I don't like about that is I would have to add code for that to every form that I use this control on. I was hopping to make the object independent of the host.
>
>>What about the Popup.StaysOpen property? Looks as if setting that to false should cause the popup to close automatically when it loses focus?
>
>This was a cool idea. Unfortunately it seems a bit buggy, probably because by default the focus stays on the textbox.
>
>It seems to work the first time.
>
>But it consumes the mouse click for the move. So you have to click twice to move the form.
>
>After the first move, the popup does not reappear. And toggling StaysOpen does not seem to help. I think I could make it work by disposing and recreating the popup... But with the mouse click not working right, I think I would rather not go that route.
>
>I looked into VisualParent, but I can't get all the way to an object that has a move event with that.
>
>I looked into Application.Current but it returns null. :(
>
>I'm running out of ideas.

I thought the same about the shortcomings of needing code in any form that uses the control.
I tried the 'StaysOpen' idea on a simple popup and (apart from the need for the extra click which you witnessed) it worked consistently so maybe your control could be tweaked somehow.

Another possiblility (not tested):
Create a subclass of ElementHost to hold the WPF control. In its constructor you could then use FindForm() to get a reference to the WinForm and hook up the Forms Move event (etc) to code in the WPF control to close the popup.

The problem with that is that even if it solves for Winforms the problem still exists in a WPF environment. I'm not sure what the advantage of using the CreateRootPopup as per the example is - have you tried the simpler approach of just using your control as content of a popup? Of course, there may be no advantage there either - but at least it's simpler to comprehend :-}

Regards,
Viv

>
>>>>Ooof! More than I bargained for <g>
>>>
>>>hehe, ya it is a bit of code. But it's a decent start on an item that is commonly wanted and not available in WPF yet. IF we get it spiffed up I'm willing to post the finnal code.
>>>
>>>>I was intially intrigued by 'The Popup does not stay with the textbox if the window is moved' and wonder why that would be the case.
>>>>I think I'm well behind you on the learning curve on this one and I'm also tied up for the next couple of days but I do want to play with it when I get time....
>>>>Regards,
>>>>Viv
>>>
>>>I'm in no rush on this one.
>>>
>>>The sample code for the popup used this rather crude method in the window code. (It makes the popups flicker when you move the window.)
>>>
>>>
>>>void Window1_LocationChanged(object sender, EventArgs e)
>>>  {
>>>  if ((bool)showDesc.IsChecked)
>>>    {
>>>    TogglePopups(false);
>>>    TogglePopups(true);
>>>    }
>>>  }
>>>
>>>
>>>But since I want to use this as a control, I need to find a different way. Plus in this case just closing the popup when the window moves would be fine.
>>
>>The above code certainly seems a bit of a kludge - but if you're happy to have the popup close then just 'TogglePopups(false);' in the event handler should do it? Of course you'd need the same behaviour for any resizing as well.
>>
>>What about the Popup.StaysOpen property? Looks as if setting that to false should cause the popup to close automatically when it loses focus?
>>REgards,
>>Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform