Taskbar refreshes when open folder dialoge box

47 Views Asked by At

I am creating a WPF application and in order to select folders I am using 'System.Windows.Forms.FolderBrowserDialog()' folder selection dialog box. When I launch my application and press on 'Select Folder' button to launch folder dialog box it refreshes TaskBar or which is a weird behavior. But when i press the same button second time on-wards and launch Folder dialog box then it does not refreshes Taskbar. I am looking to have the same behavior at First time when i launch my application. Need help to achieve this.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void TxtSelectFolder_Click(object sender, RoutedEventArgs e)
    {
        using (var ofd = new System.Windows.Forms.FolderBrowserDialog())
        {
            ofd.RootFolder = Environment.SpecialFolder.Desktop;

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TxtDirPath.Text = ofd.SelectedPath;
            }
        }
    }
}

MainWindow.xaml

   <Grid>
   <Button x:Name="TxtSelectFolder" Content="Select Folder" HorizontalAlignment="Left" Margin="74,65,0,0" VerticalAlignment="Top" Width="75" Click="TxtSelectFolder_Click"/>
   <TextBlock x:Name="TxtDirPath" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Margin="74,99,0,0"/>
   </Grid>

I am using Win 10 machine 64-bit and also the same behavior on Win 7 machine.

Looking for any suggestion to come over with this issue.

0

There are 0 best solutions below