Showing posts with label Petzold. Show all posts
Showing posts with label Petzold. Show all posts

Wednesday, November 12, 2008

Petzold's book Applications=Code+Markup

I was a little surprised that there was no one in the MSDN discussion group about the book.
I just bought the book, and started on chapter 1. I also downloaded the Zip files with the vb equivalents of Petzold's book.
Problems:
1. OnSession Ending does not work, so that there seemed to be no way to prevent an application from exiting when you click the "X" on the last window.
I found a workaround using a windows intercept as follows:
--------------
Public Sub WindowsClosing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Dim x = CType(sender, Window)
If Me.Windows.Count = 1 Then
e.Cancel = MsgBox("Do you wish to close the last window and exit the program?", MsgBoxStyle.YesNo) = MsgBoxResult.No
End If
End Sub
---------------
This works but is a bit of a cludge.
=====================
2. If you use the normal Create WPF project, you must delete Application.xaml and Windows1.xaml or the code in Petzold will not work as provided. Furthermore, if you are using "STRICT" you need to fix the lack of a cast in MyWPFExtension from cType (Global.System.Windows.Application.Current,Application)What is happening here?
I need to investigate how the automatically generated code is used.