I have a seemingly simple issue: a popup that's causing me trouble looks like this in a stripped-down version (the complete version has a spinner UserControl within the Border element, but the strange behavior is the same with or without). The XAML is this:
<Popup Name="PleaseWaitPopup" Placement="Center" IsOpen="False" StaysOpen="True" Opened="PopupOpened" Closed="PopupClosed">
<Border Width="200" Height="200" Padding="20" Background="#222">
<StackPanel Orientation="Vertical">
<TextBlock Name="WaitHeadTxt" Margin="0 0 0 36" Style="{StaticResource PopupHeadStyle}" VerticalAlignment="Top" FontSize="16"></TextBlock>
<Border Width="60" Height="60">
</Border>
</StackPanel>
</Border>
</Popup>
All of the elements (PopupOpened(), PopupClosed(), PopupHeadStyle) are well tested and work fine in lots of other popups within the same project.
In response to a user action, I want to open this popup before starting something that takes several seconds to complete (trying to hook up a device via WiFi). The code is again simple:
PleaseWaitPopup.IsOpen = true;
try
{
wifiDeviceProvider = new PtpIpProvider();
DeviceManager.AddDevice(wifiDeviceProvider.Connect("192.168.1.1"));
}
catch (Exception ex)
{
...
}
In my test case, I don't connect an external device, so the WiFi connection attempt comes back with a timeout after 10s. The popup consistently only opens AFTER the timeout, which I don’t get. No other popup is open at this point.
I tried this with other action code (an FTP transfer rather than the WiFi connection) - the issue remained, so it's unlikely that the WiFi connection code has anything to do with this. Tried making things asynchronous by opening the popup, or the WiFi connection, or both, in a separate thread via "this.Dispatcher.Invoke(() => { ... });" , but none of this made any difference.
Any ideas what I am missing here? Must be something silly, but I can't seem to figure it out. Thanks!