Results 1 to 15 of 15

Thread: [RESOLVED] BusyWindow is not draging with MainWindow if I drag and drop MainWindow

  1. #1

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Resolved [RESOLVED] BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    MainWindow xaml codes are here;

    MainWindow vb codes are here;

    BusyWindow xaml codes are here;

    BusyWindow vb.net codes are here;


    My question is here;
    Last edited by Kram Kramer; Aug 19th, 2018 at 11:25 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    At a glance, I'm not seeing anything in your code that would make the two windows stay in sync. Why exactly do you think they should?

  3. #3

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Quote Originally Posted by jmcilhinney View Post
    At a glance, I'm not seeing anything in your code that would make the two windows stay in sync. Why exactly do you think they should?
    Code:
    myBusyWindow.Owner = Application.Current.MainWindow

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    You appear to be under a misapprehension about what that Owner property does. The documentation for that property, which you should have read well before posting about this topic, has this to say:
    Once this relationship is established, the following behaviors are exhibited:
    If an owner window is minimized, all its owned windows are minimized as well.
    If an owned window is minimized, its owner is not minimized.
    If an owner window is maximized, both the owner window and its owned windows are restored.
    An owner window can never cover an owned window.
    Owned windows that were not opened using ShowDialog are not modal. The user can still interact with the owner window.
    If you close an owner window, its owned windows are also closed.
    If an owned window was opened by its owner window using Show, and the owner window is closed, the owned window's Closing event is not raised.
    There's nothing there about the owned window moving with the owner or vice versa. If you want that behaviour then you would have to code it yourself. That would mean the owned window handling the appropriate event of the owner and then positioning itself relative top that owner. I've done that before rather simply in Windows Forms and I would expect it to be fairly similar, although not identical, in WPF.

  5. #5

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Hi jmcilhinney,

    Please click following link and read the #17th post.
    Last edited by Kram Kramer; Aug 19th, 2018 at 11:25 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    I'm not really sure what you're asking or implying. If you don't want the user to be able to interact with the calling window while the other window is showing then you should call ShowDialog. I'm not sure why you were told otherwise but that's how it works. You call Show if you want to be able to interact with either window and ShowDialog if you want to interact only with the second window. The point of an owned window or modeless dialogue is to create a tool window sort of thing. A classic example is the Find & Replace window in VS.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Please do not edit posts (unless it is just a couple of minutes after you first posted it), because it causes confusion and/or annoyance. It is better to post a new reply instead.

    It also makes things harder if you split your question over multiple threads like this, because it means that all of us who are trying to help you (even if we don't reply) have to go around looking for all of the relevant information - instead of it being in one place.

    In this case you should have just replied to this thread, because this question is not the same as the one at the start of the other thread (so it doesn't belong there).

    To save others the effort, here is the other post:
    Quote Originally Posted by Kram Kramer, from the other thread
    Quote Originally Posted by techgnome View Post
    In the button click event, create an instance of the wait form, show it (not as a dialog though)

    Our code is still wrong...

    We have used
    Code:
    myBusyWindow.Show()
    but this video https://www.youtube.com/watch?v=yZYAaScEsc0 used
    Code:
    myBusyWindow.ShowDialog()
    as you can see here https://prnt.sc/kk4pom



    The User should not interact with MainWindow when BusyWindow is processing...

    So, our code is not okey

    Any suggestion?
    Using .ShowDialog might be the wrong way to go in this case, because it means only that window can run code (the window that called it can't do anything).

    If you don't want users to interact with a window, you can set Enabled to false (but it has been a while since I used WPF, so it may be a different property name).

  8. #8

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    If I change techgnome's code from
    Code:
    myBusyWindow.Show()
    to
    Code:
    myBusyWindow.ShowDialog()
    then the code sticks on the this line
    Code:
    myBusyWindow.ShowDialog()

  9. #9

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Using .ShowDialog might be the wrong way to go in this case, because it means only that window can run code (the window that called it can't do anything).

    If you don't want users to interact with a window, you can set Enabled to false (but it has been a while since I used WPF, so it may be a different property name).
    I think using .ShowDialog is correct way as youtube video does.

    To make MainWindow.IsEnable = False is not good idea because nobody is doing this...

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    I would suggest that the most appropriate way to go here is to have the waiting window accept a delegate and have it invoke that on a secondary thread. The main window would create the waiting window, pass it the delegate and then display it by calling ShowDialog.

  11. #11

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Quote Originally Posted by jmcilhinney View Post
    A classic example is the Find & Replace window in VS.
    You can interact with MainWindow during Find & Replace window is open as it should be.

    But BusyWindow is different thing. The user should not interact with MainWindow during BusyWindow is open.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Here's a quick example I just threw together in WinForms. The code in the waiting window can look something like this:
    vb.net Code:
    1. Public Class Form2
    2.  
    3.     Private ReadOnly method As [Delegate]
    4.     Private ReadOnly args As Object()
    5.  
    6.     Public Sub New(method As [Delegate], ParamArray args As Object())
    7.         ' This call is required by the designer.
    8.         InitializeComponent()
    9.  
    10.         ' Add any initialization after the InitializeComponent() call.
    11.  
    12.  
    13.         Me.method = method
    14.         Me.args = args
    15.     End Sub
    16.  
    17.     Private Async Sub Form2_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
    18.         Await Task.Run(Sub() method.DynamicInvoke(args))
    19.  
    20.         Close()
    21.     End Sub
    22.  
    23. End Class
    The form requires a delegate and optionally accepts arguments too. Immediately after it's displayed, the form invokes that delegate asynchronously and awaits it's completion. Because the delegate is invoked within a Task that is awaited, the UI is does not freeze while the delegated method is being executed. Once the method completes then the Task also completes and execution continues and the form closes itself. The calling window can look something like this:
    vb.net Code:
    1. Imports System.Threading
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    6.         Using dlg As New Form2(New Action(Of Integer)(AddressOf DoSomeWork), 10)
    7.             dlg.ShowDialog()
    8.         End Using
    9.     End Sub
    10.  
    11.     Private Sub DoSomeWork(seconds As Integer)
    12.         Thread.Sleep(1000 * seconds)
    13.     End Sub
    14.  
    15. End Class
    Wherever is appropriate - in this case, in the Click event handler of a Button - an instance of the waiting form is created and an appropriate delegate and corresponding arguments are passed to the constructor. It could be any method you wanted with any arguments you wanted. In this case, it's a method that takes a number of seconds and simply waits for that long, but you can do any work you like there. You then call ShowDialog to display the waiting form, which invokes the specified method and then closes when it completes. You can try that for yourself and see that the dialogue can be dragged around as much as you like but it will not allow access to the calling form. You can do pretty much the exact same thing in WPF.

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Quote Originally Posted by Kram Kramer View Post
    You can interact with MainWindow during Find & Replace window is open as it should be.

    But BusyWindow is different thing. The user should not interact with MainWindow during BusyWindow is open.
    I know that. That's what I'm telling you, i.e. that you should not be using an owned window in this case because owned windows don't provide the functionality that you want. You never should have set that previous thread as Resolved because your issue wasn't resolved. You've now asked a different, irrelevant question here and we've had to go back to the original issue.

  14. #14

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    131

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    Hi jmcilhinney,

    Could you please post WPF code with BackgroundWorker if possible?
    Because your WinForm code is very complicated for me...

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: BusyWindow is not draging with MainWindow if I drag and drop MainWindow

    I won't be posting any more code. I've provided an example and I've explained the principle. It's for you to adapt and apply to your own situation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width