如何使WPF PopUpControl保持粘性? [英] How to Make WPF PopUpControl Sticky?

查看:100
本文介绍了如何使WPF PopUpControl保持粘性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在使用WPF自己的弹出控件,该控件提供了一种在需要的位置弹出通知的好方法,并可以使用动画!在我的情况下,通知会在按钮顶部提示(在UserControl内部).

唯一的问题是,当我在窗口中使用UserControl并调整其大小或更改其位置时,提示的弹出窗口将保留其原始位置,而不会随按钮移动.

如何使用目标按钮使弹出窗口粘滞"?

这是我的Xaml

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

<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>



如图所示,目标将是"myButton",并且使用popUpnotifyIcon.IsOpen属性在代码中处理显示/隐藏.

我试图钩住用户控件LayoutUpdated事件中的弹出窗口重绘,但它导致了无限循环,因为popUpnotifyIcon.IsOpen状态更改也启动了LayoutUpdated,它一次又一次地启动了该事件...

希望你有主意:)



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!

推荐答案

将其位置相对于与其相关的按钮的位置进行绑定.
Bind it''s location to be relative to the position of the button it''s related to.


此对话线程介绍了如何制作粘性WPF窗口.

snapping-sticky-wpf-windows [
This conversation thread covers making sticky WPF windows.

snapping-sticky-wpf-windows[^]


这篇关于如何使WPF PopUpControl保持粘性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆