我有一个带有网格的 WPF 主窗口,并且我添加了一个 WPF 弹出窗口,以便在单击按钮时向用户询问额外信息。但问题是,当其他桌面窗口移动到弹出窗口上时,弹出窗口覆盖了其他桌面窗口。如何解决此问题,以便弹出窗口仅位于 WPF 主窗口的顶部,而不是其他桌面窗口。当设置为始终在顶部时,弹出窗口的行为就像任务管理器!
如果您使用以下代码,您将看到弹出窗口位于顶部。因此,将任何其他桌面窗口移到弹出窗口上,弹出窗口将覆盖其他桌面应用程序!请注意,我不想使用 StaysOpen="False"。
<Grid>
<Popup Name="myPopup" Placement="Center" IsOpen="True">
<StackPanel Background="Green" >
<TextBox Width="200" Margin="0,0,10,0"/>
<Button Name="closePopupBtn" Content="close" Width="100" />
</StackPanel>
</Popup>
</Grid>
Run Code Online (Sandbox Code Playgroud) 您好我有以下代码创建任务.然后将其设置为开始.该任务旨在添加对ConcurrentBag列表的响应.但等待似乎并不等待完成所有任务.但他们被标记为已完成.列表中只有一个任务.使用时效果很好Task.Run!
public async void RunT1()
{
DoesNotWork();
}
public async void RunT2()
{
DoesWork();
}
public async void DoesNotWork()
{
ConcurrentBag<string> concurrentBag = new ConcurrentBag<string>();
List<Task> taskList = new List<Task>();
Task task1 = new Task(async () =>
{
var xml = await LongWorkingMethod();
concurrentBag.Add(xml);
});
taskList.Add(task1);
taskList[0].Start();
await Task.WhenAll(taskList);
if (concurrentBag.Count > 0)//concurrentBag is empty even though the task has finished
{
Debug.Print("success");
}
}
public async void DoesWork()
{
ConcurrentBag<string> concurrentBag = new ConcurrentBag<string>();
List<Task> …Run Code Online (Sandbox Code Playgroud)