Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All!

Im using WPF own popup control which provides nice way to popup notifications on wanted place with ready to use animation! In my case notification is prompted top of the button (Inside of UserControl).

Only problem is that when I use my UserControl in window and resize or chage its position my prompted popup will remain its original place, it wont move with button.

How I make my popup "sticky" with target button?

Here is my Xaml

XML
<Popup x:Name="popUpnotifyIcon" AllowsTransparency="True" PopupAnimation="Fade" Placement="Top" PlacementTarget="{Binding ElementName=myButton}" HorizontalOffset="0" VerticalOffset="20" >
    <Viewbox VerticalAlignment="Top" >
        <Image Height="50" Width="50" Source="/MyImage.png" ></Image>
    </Viewbox>
</Popup>


As it shows target will be "myButton" and showing/hiding is handled in code using popUpnotifyIcon.IsOpen property.

I tried to hook popup redrawing in usercontrols LayoutUpdated event but it leaded endless loop because popUpnotifyIcon.IsOpen state change launches also LayoutUpdated which launches that event again and again...

Hope you got idea :)

Cheers!
Posted
Updated 17-Aug-11 2:24am
v2

Bind it's location to be relative to the position of the button it's related to.
 
Share this answer
 
Comments
paleGegg0 17-Aug-11 8:48am    
Hi and thanks for your time! I dont fully understand relative binding to button, could you kindly post a code snippet?
paleGegg0 18-Aug-11 2:29am    
Oh, now I got it. Thanks for the tip, works nicely!
Member 8722733 27-May-14 17:48pm    
i am afraid i dont understand either, what did you end up doing?
This conversation thread covers making sticky WPF windows.

snapping-sticky-wpf-windows[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900