简体   繁体   中英

Displaying a Second Form in WPF

I have a main form and as sub form. I need the main Form to display the sub Form and pass into the constructor an object. When the sub Form is done it needs to destroy itself so the cycle can be repeated.

Currently I declared the sub form globaly

Public GlobalWindowBookmark As WindowEditBookmark

I then create the form and pass it the object.

GlobalWindowBookmark = New WindowEditBookmark(CType(_MenuBookmark, BookmarkItem))
GlobalWindowBookmark.Visibility = Windows.Visibility.Visible

This just does not feel right and also allows for multiple windows. Any help would be appreciated.

Thanks,

Do you want the sub form to be a modal dialog - ie not allow the user to interact with the main form while it's up? If so, you could do something like this (sorry if my VB is not completely correct, I use C# normally):

Dim wndBookmark as New WindowEditBookmark(CType(_MenuBookmark, BookmarkItem))
wndBookmark.ShowDialog()

There is also a Show method, which displays the window but doesn't make it modal. That might help if you don't want the subform to be modal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM