小编Kel*_*sie的帖子

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

如果我将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)

c# wpf xaml

5
推荐指数
1
解决办法
692
查看次数

将代码放在等待的任务结束时与在等待之后放置代码之间的区别:

这段代码应该......

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)

...?

c# async-await c#-5.0

1
推荐指数
1
解决办法
70
查看次数

标签 统计

c# ×2

async-await ×1

c#-5.0 ×1

wpf ×1

xaml ×1