Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Dialog Window Becomes Black Upon Closing

$
0
0

Main screen opens a dialog window (win) upon button click.

Private Sub myBtn_click(sender As Object, e As RoutedEventArgs) Handles myBtn.Click
    Dim w As New win
    w.Owner = Me
    Dim d As DataRowView
    If w.ShowDialog = True Then
        'Do something
    End If
    w = Nothing
    d = Nothing
End Sub

Win opens and does stuff with two datasets it creates. Win's WindowStyle was a SingleBorderWindow. So it had the standard tools in the upper left for maximizing, minimizing, and closing.

Has button for Save and Cancel.

Clicking Save and Cancel seem to work fine.

However, when I close win using the standard window close tool in the upper left, SOMETIMES it would work fine and other times win's would turn BLACK and would just hang there until I minimized it. The calling window went back to do its thing.

If I make win's WindowStyle None then the user has no standard window close tool to make this annoyance. But that's crazy.

It must be that I'm not closing the window and releasing the resources properly, with Garbage Collection or Mr. Disposal getting in the way.

How can we make it work properly?

Here's code for win. Thanks

Public Class win
    Private ds1 As New DataSet
    Private ds2 As New DataSet
    Private Sub btnSave_Click(sender As Object, e As RoutedEventArgs) Handles btnSave.Click
        Me.DialogResult = True
        Me.Close()
    End Sub
    Private Sub btnCancel_Click(sender As Object, e As RoutedEventArgs) Handles btnCancel.Click
        CancelMe()
    End Sub
    Private Sub CancelMe()
        Me.DialogResult = False
        Me.Close()
    End Sub
    Private Sub win_Closing(sender As Object, e As ComponentModel.CancelEventArgs) Handles Me.Closing
        ds1.Dispose()
        ds2.Dispose()
        ds1 = Nothing
        ds2 = Nothing
    End Sub
End Class


Harlan Black


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>