Jeśli zmienię StaysOpen na "True", pojawi się wyskakujące okienko, ale nie zamyka się po kliknięciu poza nim, więc to nie jest to, czego chcę.Wyskakujące okienko nie otwiera się, jeśli StaysOpen = "False"
Oto odpowiedni kod 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>
A oto kod 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
}
Każdy pomysł, dlaczego mój okienko nie pojawi się z StaysOpen = "false"?
możliwy duplikat [StayOpen = "False" z odziedziczonymi popupami] (http://stackoverflow.com/questions/21464557/stayopen-false-with-inited-popups). Proszę zobaczyć moją odpowiedź z tego połączonego pytania na rozwiązanie twojego problemu. – Sheridan
Nie wydaje mi się, aby odpowiedź na pytanie, które łączysz, dotyczy tego pytania. – Kelsie
Czy Twój opublikowany plik xaml jest kompletny? Obecnie wygląda na to, że dodajesz 'Zachowanie' jako dziecko do' Border' niż w ' ... i: Interaction.Behaviors>' –
Viv