c# - 用户做出选择后保持 WPF 弹出窗口打开

标签 c# .net wpf

当用户从主网格中选择记录时,我会出现一个小的弹出窗口。我想在用户做出选择后保持此窗口打开,直到他或她单击取消。这是我的小代码。如果我注释掉 this.close() 方法,则控制永远不会返回以执行其余代码。

private void ClickSubmit(object sender, RoutedEventArgs e)
{
    try
    {
        IsCancelled = false;
        // Figure out to keep this little window open after clicking submit !!
        this.Close();
        return;
    }
    catch (Exception ex)
    {
        ex.ToString();
    }
}

private void ClickCancel(object sender, RoutedEventArgs e)
{
    try
    {
        Trace.WriteLine("Popup exit !");
        IsCancelled = true;
        this.Close();
        return;
    }
    catch (Exception ex)
    {
        ex.ToString();
    }

}

OrdRec or = lvOrders.SelectedItem as OrdRec;

PxQtyPopup pop = new PxQtyPopup(or);
//pop.ShowDialog();
pop.Show();

if (!pop.IsCancelled) // check whether price/qty change submitted or popup window was cancelled
    (DCtxt as OrdViewModel).ModifyOrder(or, int.Parse(pop.Qty), decimal.Parse(pop.Px));

最佳答案

IsOpen 绑定(bind)到合适的 bool 值,这将打开或关闭弹出窗口。下面的示例使用 ToggleButton 的 OpenState( bool 值)来打开/关闭弹出窗口。

<ToggleButton Height="30" Width="60"             
                x:Name="OpenState">
    <StackPanel>
        <TextBlock Text="{Binding IsChecked, ElementName=OpenState}"
                    FontSize="18"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center">
        </TextBlock>

        <Popup Name="myPopup"
                IsOpen="{Binding IsChecked, ElementName=OpenState}">


            <TextBlock Name="myPopupText"
                       Background="LightBlue"
                       Foreground="Blue">Popup Text</TextBlock>

        </Popup>

    </StackPanel>
</ToggleButton>

关于c# - 用户做出选择后保持 WPF 弹出窗口打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66465551/

相关文章:

c# - 如何确定计算机是否连接到 novell eDirectory 或 Microsoft ActiveDirectory?

c# - 我的 SVN 代码存储库中是否需要 bin\debug\appName.vshost.exe 和 appName.vshost.manifest?

c# - 使用单一方法返回不同类型的数据

c# - .net Rx : in-order batch-processing of messages

c# - 将二进制文件字节数组发送到 web api 方法

c# - 如何使用 C# 和 LINQ to Twitter 库更新 Twitter 上的状态

c# - 如何在 C# 中的 Windows 应用程序中创建单个文件设置?

.net - 各种 .NET Framework 版本的操作系统兼容性

c# - 允许用户删除我的应用程序正在使用的文件?

c# - 如何使用 Caliburn.Micro 制作导航服务?