locked
Runnin an app with two windows (Rainer Engblom) - 2/10/2008 11:55 PM PST RRS feed

  • Question

  • By: Rainer Engblom


    Hello all,
    I've added a window in Blend with File->New Item, so I have Window1 and 
    Window2 in my application.
    In Window1 I have a button for opening Window2. The button's click event 
    calls OpenTreeWindow, which looks as follows:
    
    private void OpenTreeWindow(object sender, RoutedEventArgs e)
            {
                Window2 NewWindow = new Window2();
                NewWindow.Show();
                NewWindow.Owner = this;
            }
    
    The owner line is there now, but it may be removed, if we want to be able to 
    run window2 alone...
    
    So far, so good, The button opens the new window. 
    
    My boss wants rounded windows and dialogues, so we use WindowStyle=None and 
    Allow Transparency=Yes with Windows background and border set to 'no brush'. 
    Then we just add our own paths as background. This works ok too. Ofcourse in 
    this case we need to make our own minimize and close window buttons, and then 
    some code, all this works well for window1. In Window2 I don't seem to get 
    any buttons to react to actions. It seems as if window2 is complitely 
    inactive all the time. Furthermore, on window event 'MouseLeftButtonDown' I 
    call a function  StartDrag (to enable re-positioning of window):
    
    private void StartDrag(object sender, 
    System.Windows.Input.MouseButtonEventArgs e)
            {
                this.DragMove();
            }
    
    This has worked well for Window1, but not anymore. I cannot move either 
    window, though both have this code implemented.
    Finally I was wondering what approach would be best for assuring that only 
    one instance of Window2 can be opened. Both Window1 and Window2 should be 
    allowed to be used separately and/or simultaniously.
    
    So, in short:
    
    1) Why doesn't Window2 react to anything?
    2) Why doesn't DragMove work for any window now?
    3) How will I make sure that only one instance of each window can be opened?
    
    And, I should add that my skills in C# and XAML are very limited.
    
    Best regards,
    Friday, February 22, 2008 6:40 PM

All replies

  • By: Rainer Engblom


    I realise now that I don't even know how to reference objects from one 
    window to another. How can I call methods in the other window? What is the 
    name of my window1 instance?
    
    Rainer Engblom
    Monday, February 25, 2008 10:54 PM
  • By: Jeetendra Kukreja


    Hi,
    
    I tried your scenario and it seemed to work fine for me. I have attached a 
    sample project that works as per your requirements. You could check that 
    your event handlers are wired correctly. It might be that the wrong element 
    might have been hooked up instead of the window.
    
    Thanks,
    Jeetendra Kukreja
    SDET, Expression Blend
    [MSFT]
    
    "Rainer Engblom" <RainerEngblom@discussions.microsoft.com> wrote in message 
    news:40BD21EF-E375-484C-B02A-55FD4AD3A845@microsoft.com...
    > Hello all,
    > I've added a window in Blend with File->New Item, so I have Window1 and
    > Window2 in my application.
    > In Window1 I have a button for opening Window2. The button's click event
    > calls OpenTreeWindow, which looks as follows:
    >
    > private void OpenTreeWindow(object sender, RoutedEventArgs e)
    >        {
    >            Window2 NewWindow = new Window2();
    >            NewWindow.Show();
    >            NewWindow.Owner = this;
    >        }
    >
    > The owner line is there now, but it may be removed, if we want to be able 
    > to
    > run window2 alone...
    >
    > So far, so good, The button opens the new window.
    >
    > My boss wants rounded windows and dialogues, so we use WindowStyle=None 
    > and
    > Allow Transparency=Yes with Windows background and border set to 'no 
    > brush'.
    > Then we just add our own paths as background. This works ok too. Ofcourse 
    > in
    > this case we need to make our own minimize and close window buttons, and 
    > then
    > some code, all this works well for window1. In Window2 I don't seem to get
    > any buttons to react to actions. It seems as if window2 is complitely
    > inactive all the time. Furthermore, on window event 'MouseLeftButtonDown' 
    > I
    > call a function  StartDrag (to enable re-positioning of window):
    >
    > private void StartDrag(object sender,
    > System.Windows.Input.MouseButtonEventArgs e)
    >        {
    >            this.DragMove();
    >        }
    >
    > This has worked well for Window1, but not anymore. I cannot move either
    > window, though both have this code implemented.
    > Finally I was wondering what approach would be best for assuring that only
    > one instance of Window2 can be opened. Both Window1 and Window2 should be
    > allowed to be used separately and/or simultaniously.
    >
    > So, in short:
    >
    > 1) Why doesn't Window2 react to anything?
    > 2) Why doesn't DragMove work for any window now?
    > 3) How will I make sure that only one instance of each window can be 
    > opened?
    >
    > And, I should add that my skills in C# and XAML are very limited.
    >
    > Best regards, 
    
    Monday, February 25, 2008 10:55 PM