5
如果將StaysOpen更改爲「True」,彈出窗口會顯示,但當您單擊外部時它不會關閉,所以這不是我想要的。如果StaysOpen =「False」,彈出窗口不會打開
下面是相關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 = 「假」 現身?
[StayOpen =「False」with inherited popups](http://stackoverflow.com/questions/21464557/stayopen-false-with-inherited-popups)可能有重複。請看這個鏈接問題的答案,以解決您的問題。 – Sheridan
我不覺得你鏈接的問題的答案適用於這個問題。 – Kelsie
您發佈的xaml是否完整?目前,您看起來像將行爲作爲孩子添加到「邊框」而不是「 ...」。 i:Interaction.Behaviors> – Viv