locked
new to wpf RRS feed

  • Question

  • Hello,

     

    I'd like to make a small application that first asks the user to choose a folder from a explorer view, and then displays a dialog window where some elements depend on the folder that has been chosen.
    So basically there are two windows. I'm thinking of making a button in the second window that allows to go back to the previous window and change the directory. The first window should at least have a small text explaining what to do, and maybe some options to check too.
    My question is : how can I create a project that has two windows ? From what I can see, the designer only shows one dialog window.

    I also have another question that is I think related, even though it's not something I need to do right now : how could I have a MDI window, with file, edition, tools, etc., in the designer ? (it's the same question, but instead of 2 windows one after the other, it's 2 windows inside the same container, and with the usual commands for a software).

    Thanks.

    Friday, November 26, 2010 2:41 AM

Answers

  • Jenny,

    in visual studio you create a new WPF application.  There is an initial window in the application called MainWindow. Add some <RowDefinition>s to the Grid.  In the first row is a TreeView, in the 2nd is a <button>.

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
      <Grid>
      <Grid.RowDefinitions>
       <RowDefinition Height="*"></RowDefinition>
       <RowDefinition Height="auto"></RowDefinition>
      </Grid.RowDefinitions>
    
      <TreeView Grid.Row="0"
           x:Name="tvExplorer"></TreeView>
    
      <Button Grid.Row="1"
           x:Name="butLaunch"
          Click="butLaunch_Click">Launch 2nd window</Button>
     </Grid>
    </Window>
    

    to create the 2nd window, right click the project and add a new window.  that window is a class, so to start it you code:  Window2 w2 = new Window2( ) ;   w2.Show( ) ;

    using the Show( ) method of the window class starts the new window that is independent of the first.  Use ShowDialog( ) to create the new window in modal mode where you have to close the 2nd window to return to the first.

    By storing a reference to the first window in the 2nd window, the 2nd window can update properties in the 1st window.

    regarding your design choice, look at using a Grid with 3 columns. The middle column being a GridSplitter. Then have the TreeView in a panel in the 1st column of the Grid. And another vertically oriented StackPanel in the 3rd column, displaying details from selected TreeView items in the left side column.

    -Steve

     

     

    • Proposed as answer by Sheldon _Xiao Thursday, December 2, 2010 3:27 AM
    • Marked as answer by Sheldon _Xiao Friday, December 3, 2010 5:31 AM
    Sunday, November 28, 2010 5:12 PM

All replies

  • Can someone help me please ?
    Friday, November 26, 2010 2:46 PM
  •  

    You can simply select option "Add Window" from Project Menu (in VS 08, but it should be similar in VS 10).

    Friday, November 26, 2010 3:34 PM
  • ok, thanks for the answer.

    Will that create a new independant window ?
    How could I create a window that is embedded in the first one (in a MDI document) ?

    Friday, November 26, 2010 4:10 PM
  • Can someone answer my questions from last post please ?
    Sunday, November 28, 2010 6:28 AM
  • Jenny,

    in visual studio you create a new WPF application.  There is an initial window in the application called MainWindow. Add some <RowDefinition>s to the Grid.  In the first row is a TreeView, in the 2nd is a <button>.

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
      <Grid>
      <Grid.RowDefinitions>
       <RowDefinition Height="*"></RowDefinition>
       <RowDefinition Height="auto"></RowDefinition>
      </Grid.RowDefinitions>
    
      <TreeView Grid.Row="0"
           x:Name="tvExplorer"></TreeView>
    
      <Button Grid.Row="1"
           x:Name="butLaunch"
          Click="butLaunch_Click">Launch 2nd window</Button>
     </Grid>
    </Window>
    

    to create the 2nd window, right click the project and add a new window.  that window is a class, so to start it you code:  Window2 w2 = new Window2( ) ;   w2.Show( ) ;

    using the Show( ) method of the window class starts the new window that is independent of the first.  Use ShowDialog( ) to create the new window in modal mode where you have to close the 2nd window to return to the first.

    By storing a reference to the first window in the 2nd window, the 2nd window can update properties in the 1st window.

    regarding your design choice, look at using a Grid with 3 columns. The middle column being a GridSplitter. Then have the TreeView in a panel in the 1st column of the Grid. And another vertically oriented StackPanel in the 3rd column, displaying details from selected TreeView items in the left side column.

    -Steve

     

     

    • Proposed as answer by Sheldon _Xiao Thursday, December 2, 2010 3:27 AM
    • Marked as answer by Sheldon _Xiao Friday, December 3, 2010 5:31 AM
    Sunday, November 28, 2010 5:12 PM
  • To answer the MDI question, WPF has no concept of an MDI. There are some 3rd party concoctions out there, but TDI is generally the way applications are usually being developed these days. 

     

    Also, if you create a reference to System.Windows.Forms, you can use the FolderBrowserDialog.

     

    Warm regards,
    Matt

    • Proposed as answer by Sheldon _Xiao Thursday, December 2, 2010 3:26 AM
    Monday, November 29, 2010 12:18 AM
  • Hi Jenny00,

    I am marking your issue as "Answered", if you have new findings about this issue, please unmark.

     

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Friday, December 3, 2010 5:31 AM