-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot show "open file dialog" window issue in WPF Apps #2663
Comments
|
We pivot on Environment.UserInteractive, is that not returning the correct value in 5.0? |
Looks related to dotnet/runtime#1724 (comment) |
Yeah, doesn't look like a WPF bug. Here is a self-contained repro.
<Window x:Class="test003.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:test003"
mc:Ignorable="d"
Title="MainWindow" Height="80" Width="250">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Click="OnOpenFileDialogButtonClicked" Content="Open File Dialog">
<x:Code>
<![CDATA[
void OnOpenFileDialogButtonClicked(object _, RoutedEventArgs __)
{
var dlg = new Microsoft.Win32.OpenFileDialog();
try
{
dlg.ShowDialog();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
]]>
</x:Code>
</Button>
<Label Grid.Row="1" Grid.Column="0" Content="Environment.UserInteractive: " FontWeight="Bold"/>
<Label Grid.Row="1" Grid.Column="1" Content="{x:Static sys:Environment.UserInteractive}"/>
</Grid>
</Window> /cc @danmosemsft, @merriemcgaw This has the potential to break WinForms as well. |
Thanks for the heads up @vatsan-madhavan . @Vino-Wang you might run into this testing WinForms. Can you see if we're impacted? File a WinForms issue to track if you do hit it? |
Tracking with dotnet/runtime#32929 Is this a preview 1 blocking issue? If so, I suggest a temporary workaround in WPF code. Previous to my change, Environment.UserInteractive was hard coded to true. My change copied the .NET Framework implementation over (at least, attempted to.). The quickest workaround is for you to replace the 3 uses of Environment.UserInteractive in dotnet/wpf with hard coded "true". This will give the exact same behavior as in 3.1. I don't see use of this in Winforms - I guess it uses the CommonDialog in WPF. |
It doesn't seem to affect WinForms. The checks come from WPF itself. Perhaps winforms should add these checks 😄 - no point in trying to show ux when |
Problem description: Click Open File dialog button on the app.
Actual behavior: Messagebox says "Cannot show a file dialog unless application is running in UserInterActive mode "
Expected behavior: Open file dialog window show.
**Minimal repro:**using Microsoft.Win32;
private void button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
try
{
openFileDialog.ShowDialog(); // Exception on this line
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
More detail and repro machine could be found at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1074622
We are testing this app https://github.com/NuGetPackageExplorer/NuGetPackageExplorer and most WPF apps affect by this issue.
@dotnet-actwx-bot FYI
The text was updated successfully, but these errors were encountered: