gpt4 book ai didi

c# - 如果 StaysOpen ="False",弹出窗口不会打开

转载 作者:太空狗 更新时间:2023-10-29 23:51:09 27 4
gpt4 key购买 nike

如果我将 StaysOpen 更改为“True”,弹出窗口会显示,但当您在其外部单击时它不会关闭,所以这不是我想要的。

这是相关的 XAML 代码:

<Border x:Name="popupPlacementTarget">
<i:Interaction.Behaviors>
<local:PopupBehavior>
<local:PopupBehavior.Popup>
<Popup PlacementTarget="{Binding ElementName=popupPlacementTarget}"
Placement="MousePoint"
StaysOpen="False">
<ContentPresenter Content="{Binding SomeContent}" ContentTemplate="{StaticResource SomeContentTemplate}" />
</Popup>
<local:PopupBehavior.Popup>
</local:PopupBehavior>
</i:Interaction.Behaviors>
</Border>

这是 PopupBehavior 代码:

public class PopupBehavior : Behavior<UIElement>
{
#region Dependency Properties

public static readonly DependencyProperty PopupProperty = DependencyProperty.Register(
"Popup", typeof(Popup), typeof(PopupBehavior), new FrameworkPropertyMetadata(default(Popup)));

#endregion Dependency Properties

#region Properties

public Popup Popup
{
get { return (Popup)this.GetValue(PopupProperty); }
set { this.SetValue(PopupProperty, value); }
}

#endregion Properties

#region Protected Methods

protected override void OnAttached()
{
base.OnAttached();

this.AssociatedObject.MouseDown += this.OnMouseDown;
}

protected override void OnDetaching()
{
base.OnDetaching();

this.AssociatedObject.MouseDown -= this.OnMouseDown;
}

#endregion Protected Methods

#region Private Methods

private void OnMouseDown(object sender, MouseButtonEventArgs eventArgs)
{
var popup = this.Popup;
if (popup == null)
{
return;
}

this.Popup.IsOpen = true;
}

#endregion Private Methods
}

知道为什么我的弹出窗口不会显示 StaysOpen="False"吗?

最佳答案

原来有一个祖先在鼠标按下时不分青红皂白地抓取捕获。我已更正此问题,现在一切正常。

顺便说一句,我能够通过设置 StaysOpen="True"、继承 Popup 并挂接到派生 Popup 中的全局鼠标事件来解决这个问题。当弹出窗口打开时,我会将处理程序附加到全局输入事件。然后,当收到一个事件时,我会对其进行过滤,以便我只响应鼠标左键按下事件。在处理这个事件时,如果鼠标没有悬停在弹出窗口上,我会关闭弹出窗口并分离事件。它有效,但它显然是一个肮脏的 hack,我很高兴我没有它也能正常工作。

关于c# - 如果 StaysOpen ="False",弹出窗口不会打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23546237/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com