如果我将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>
Run Code Online (Sandbox Code Playgroud)
这是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;
} …Run Code Online (Sandbox Code Playgroud) 这段代码应该......
async void SomeMethodAsync() {
this.IsDoingLongRunningWork = true;
await Task.Run(() =>
{
DoLongRunningWork();
this.IsDoingLongRunningWork = false;
});
}
Run Code Online (Sandbox Code Playgroud)
......行为与这段代码不同......
async void SomeMethodAsync() {
this.IsDoingLongRunningWork = true;
await Task.Run(() =>
{
DoLongRunningWork();
});
this.IsDoingLongRunningWork = false;
}
Run Code Online (Sandbox Code Playgroud)
...?