【发布时间】:2014-06-26 02:36:57
【问题描述】:
如果我将 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" 吗?
【问题讨论】:
-
StayOpen="False" with inherited popups 的可能副本。请查看我对此链接问题的回答,了解您的问题的解决方案。
-
我觉得你链接的问题的答案不适用于这个问题。
-
您发布的 xaml 是否完整?目前,您似乎将
Behavior作为孩子添加到Border,而不是<i:Interaction.Behaviors>...</i:Interaction.Behaviors> -
这是一个错字,它在交互行为中。我会编辑。
-
@Kelsie,您很少遇到与另一个问题完全相同的问题。关键是,如果您只想尝试一下,链接的帖子中有一个可行的解决方案。