C# WPF and GUI - Pages and Navigation

Поділитися
Вставка
  • Опубліковано 17 жов 2024

КОМЕНТАРІ • 140

  • @steffenmlgaardlarsen5463
    @steffenmlgaardlarsen5463 5 років тому +99

    1 hour of googling failed me. This video answered my question in 7 minutes - Thank you.

    • @wesleycoomans1433
      @wesleycoomans1433 4 роки тому +8

      Broke record with 4 days :D

    • @RugbugRedfern
      @RugbugRedfern 4 роки тому +8

      What is it about WPF that makes everything so hard to learn...

    • @C4rnee
      @C4rnee 3 роки тому +4

      @@RugbugRedfern There are lots of complex topics which can only be understood if you understand other complex topics, so I guess you just have to read up a ton of theory before you can actually make something that feels like it should be easy to make

    • @sergsergesrgergseg
      @sergsergesrgergseg 3 роки тому +4

      @@RugbugRedfern compared to react, wpf is so overly complicated

    • @RugbugRedfern
      @RugbugRedfern 3 роки тому +2

      @@sergsergesrgergseg I'm switching from WPF to node.js + electron now, so much easier

  • @joseangelbautistar.44
    @joseangelbautistar.44 5 років тому +40

    almost 3 hours searching exactly this on google and it was soo simple. Thank you a lot

  • @mjparsons
    @mjparsons 8 років тому +20

    +1 for the NavigationUIVisibility="Hidden". That's exactly what I was looking for!

    • @limtingfei994
      @limtingfei994 5 років тому

      Exactly! That's really annoying and complicated when I tried to disable it from the control template

  • @CodeSeekers
    @CodeSeekers 4 роки тому +10

    Best Tutorial ❤ Simple and Perfectly Explained the Topic, You saved me from attending a boring lecture of 2 hours :D , Thank you very much Sir,

  • @JUNDKGOD
    @JUNDKGOD 3 роки тому +2

    Nice tutorial for new guys like me. Simplily and clearly. maybe its not need to say on this video, but I think there is one bug here that is everytime when you click the "Page # " button, the "main“ frame is gonna creat a new page. So I think the best way is to change the funtion of the button to navigate the pages instead of creating if the page has existed.

    • @000Graffy000
      @000Graffy000 2 роки тому +1

      I was searching the comments to make sure, that somebody like me is already sayed about this. :D

  • @doj3168
    @doj3168 4 роки тому +1

    Man, you helped me with my project. You explained such thing better than Indian programmers. I express my gratitude for your job.

  • @ckpradip
    @ckpradip 4 роки тому +5

    Thanks for this video. I have done a bit of programming in C++.
    I got couple of questions :
    1. New() is not having a corresponding delete(). Will this not result in memory leak?
    2. Can these page attributes be accessed from other pages also?

    • @emmanuelasare5658
      @emmanuelasare5658 4 роки тому +1

      In c# you have to call dispose method on the object created but not every object is disposable so in that case you have to set it to null after you are done using it

  • @brigoose7945
    @brigoose7945 4 роки тому

    st question you start off in visual studio....what did you open, i usually open project/win application. What have you opened for the plain page

  • @gaminglegend372
    @gaminglegend372 4 роки тому

    Thx sooo much, a simple tutorial that gets straight to the point. Now we can safely say that youtube is more superior than google.

  • @kennylunaaa5596
    @kennylunaaa5596 Рік тому

    Does this work the same way if the navigation buttons are on the pages, instead of the main window?

  • @maulanasatyaadi
    @maulanasatyaadi Рік тому

    thanks bro, i've been learning wpf for 1 day.

  • @mr.es1857
    @mr.es1857 6 років тому

    Thank you i'm using this aproach for a WPF.
    -I have this main window with it's view model called MainViewModel.
    - This main window can hold several pages in the frame all pages have their own viewmodel.
    -I have a button in one of the pages and in it's button click i want to display a "Fly out" in the "MainWindow" . The content of this fly out depends of the page that is actually shown in the frame. This part works correctly but i can't achive to open the fly out from the page 's button click.
    -I was wondering if there is any way to do this or if you have an advice for me.

  • @niphomahlangu2733
    @niphomahlangu2733 3 роки тому

    Thank you very much. You've solved most of my problems. You're appreciated.👌🔥🔥🔥

  • @simo5465
    @simo5465 6 років тому +16

    Thank you very much :) very helpfull .
    For me work like this :
    Page1 page1= new Page1();
    Main.Content= page1.Content;
    Hope it helps somebody :)

    • @savideos6916
      @savideos6916 5 років тому +4

      In Visual Studio 2017, you can also navigate using this way:-
      Button_Click(object sender, RoutedEventArgs e)
      {
      Frame1.Navigate(new Page1());
      }
      this will do the same as..... Frame1.Content = new Page1();
      Thankyou... $@

    • @dmg4011
      @dmg4011 5 років тому

      THANK YOU

    • @Leo-kr4vw
      @Leo-kr4vw 5 років тому +5

      Thanks!
      I also added some more lines, check this:








      //*********************************************************************
      private Page1 p1;
      private Page2 p2;
      private Page3 p3;
      private void Button_Click_1(object sender, RoutedEventArgs e)
      {
      if (p1 == null)
      {
      p1 = new Page1();
      }
      Main.Content = p1.Content;
      }
      private void Button_Click_2(object sender, RoutedEventArgs e)
      {
      if (p2 == null)
      {
      p2 = new Page2();
      }
      Main.Content = p2.Content;
      }
      private void Button_Click_3(object sender, RoutedEventArgs e)
      {
      if (p3 == null)
      {
      p3 = new Page3();
      }
      Main.Content = p3.Content;
      }
      // Clear(delete) all pages
      private void Button_Click_4(object sender, RoutedEventArgs e)
      {
      p1 = null;
      p2 = null;
      p3 = null;
      Main.Content = null;
      }

  • @joybotics
    @joybotics 6 років тому +3

    Excellent and concise tutorial! Thank you.

  • @77Zamien
    @77Zamien 8 років тому +5

    Good presentation. Is this possible to do within XAML to stay more MVVM correct?

    • @ilfordgrammarschool4270
      @ilfordgrammarschool4270  8 років тому +7

      Sure, I would just set up data binding on the Content property and handle the page switching from the ViewModel. . You could even set up the page switching control using two way binding on a different element.
      Here is another MVVM approach: rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/
      Have a look here at a possible pure xaml approach: msdn.microsoft.com/en-us/library/ms750478(v=vs.110).aspx

  • @katharinamuller240
    @katharinamuller240 3 роки тому

    Is there a way to remove the buttons in Main so they don't take up space in Pages 1 + 2 ? Thanks.

  • @pashaPDX
    @pashaPDX 3 роки тому

    How to pass the data between the two pages? or to the main window? Can page1 update data that is outside the FRAME?

  • @technologynews3143
    @technologynews3143 2 роки тому

    Hallelujah !! But why this way or MVVM ?

  • @jaym9846
    @jaym9846 6 років тому

    Can I have multiple instances of a Page1 and Page2? Can I keep a page instance loaded even if it not visible?
    For example, if I have buttons Page1a, Page1b, Page2a, Page2b where clicking Page1a instantiates and displays the first instance of Page1,
    can I then click Page1b to instantiate and displays the second instance of Page1 without unloading first instance from memory?

  • @bfarhan8
    @bfarhan8 3 роки тому

    Great Explanation, one question though can I use 3 different pages in a single frame?

  • @Magnotis
    @Magnotis 4 роки тому

    Is there a way to set it so that the content of one page displays automatically? I'm trying to make a login screen and I want to use a page for my registration form, but also display my other page which has the actual login within it

  • @josephmbote4167
    @josephmbote4167 3 роки тому

    What a great short tutorial with great impact

  • @tobiassjoholm9325
    @tobiassjoholm9325 Рік тому

    What is the purpose of the frame?
    You could have just use any container element

  • @msgracebk2978
    @msgracebk2978 4 роки тому

    I am so thankful for this video.. Thanks for taking your time!!

  • @Tjulu1
    @Tjulu1 7 років тому

    How do i navigate in one form without opening a new one like this. Is the only solution using XAML or can I do the same thing with only C#? IF thats the case.. How do I do it?

  • @nathanng2247
    @nathanng2247 4 роки тому

    Will the page1 be freed automatically after Navigating to page2?

  • @mr.es1857
    @mr.es1857 6 років тому

    well i know that this question would out of context but... i´m having problems when i try too shutdown my app im using the property of ShutdownMode in the App.xaml. Putting it's value to "OnLastWindowClose" and it does't work. When i close the app and look for it in my computers task manager i can see that the app is running in second plane.

  • @itskrypton2662
    @itskrypton2662 3 роки тому +1

    How do i make it go back on the default screen content?

  • @TwoToedSloth
    @TwoToedSloth 2 роки тому

    Very Helpful. Thank you from the future

  • @amiransari8483
    @amiransari8483 4 місяці тому

    nice work. simplicity is the best

  • @sadiq3690
    @sadiq3690 5 років тому +1

    can a window be displayed in frame the same way as page ?

  • @shjin
    @shjin 4 роки тому +2

    Simple and very effective explanation!

  • @recepcakir4866
    @recepcakir4866 2 роки тому

    How to make the page shown in frame full screen?

  • @a_bahar
    @a_bahar 4 роки тому

    As you know or not. The Grid control has RowDefinitions and ColumnDefinitions

  • @jonasb2047
    @jonasb2047 8 років тому

    Can't believe this guy works in a public school haha he knows more than some of my University lecturers

  • @polyviospatseadis9777
    @polyviospatseadis9777 Рік тому

    Very nice video but how i can change the main content inside the page2 for example

  • @lawkaijian618
    @lawkaijian618 Рік тому

    why it showing System.InvalidOperationException: root element is not valid for navigation.' Need Help. Please!!

  • @tomken5919
    @tomken5919 7 років тому

    How do you navigate back to the home screen though? Once I navigate the page 1 and 2, I am stuck there. How do I get back to the main window?

  • @johnolive6634
    @johnolive6634 4 роки тому

    Thanks very much
    Am trying to develop and I need to create an editable page like that of Microsoft word which can also automatically insert pages. But don't have any idea.
    Any information or video will do.
    Thanks in advance

  • @Siuulolñ
    @Siuulolñ 3 роки тому

    Can you do the same but instead of Pages using User Controls?

  • @datpudding5338
    @datpudding5338 Рік тому

    Seven years after upload the best solution I found - sadly I got both pages to shine through each other xD

  • @SLSL-yy4um
    @SLSL-yy4um 7 років тому

    You could use a grid inside the stack panel for your button too

  • @datathree
    @datathree 7 років тому

    Hey, can I increase the Size of the new Page beacuse it is way to small for my project every time i try to increase it it wouldnt work

  • @Eh_814
    @Eh_814 4 роки тому

    What is the difference to usercontrols?

  • @kiwichi4488
    @kiwichi4488 6 років тому

    Now how do you page these pages scrollable if they are too large for the frame?

  • @jaycedam1234
    @jaycedam1234 4 роки тому +2

    Short and simple, thank you!

  • @krishnavankadari
    @krishnavankadari 7 років тому +1

    That's so cool presentation, thanks a lot👏🏾👏🏾👏🏾

  • @ritamgiri5872
    @ritamgiri5872 Рік тому

    How I can navigate from Page to Mainwindow?

  • @MrWatchyour6
    @MrWatchyour6 8 років тому +1

    I am trying to do something similar but I can't find it to work. I have a button (button1) in page 1 which I want to have me direct to Page2. I tried this in Page1.xaml.cs
    private void button1_Click(object sender, RoutedEventArgs e)
    {
    Main.Content = new Page2();
    }
    I know Main doesn't exist in Page1 but I don't know how I should do it. Any help?

    • @agoldfish9239
      @agoldfish9239 6 років тому

      instead of Main.Content do this:
      Page2 p2 = new Page2();
      this.NavigationService.Navigate(p2);

  • @sadiq3690
    @sadiq3690 5 років тому

    Very nice and simpy way of doing work.

  • @janiss.7828
    @janiss.7828 3 роки тому

    ich kriege immer die exeption "Das Stammelement ist für die Navigation nicht gültig" weiß jemand woran das liegt?

  • @amanverma193
    @amanverma193 4 роки тому

    You made my day....Thanks a million

  • @hiromijorge400
    @hiromijorge400 3 роки тому

    hi, thanks for the tutorial,
    Severity Code Description Project File Line Suppression State
    Error XLS0509 Property elements cannot be in the middle of an element's content. They must be before or after the content. WpfApp1 C:\Users\hirom\source
    epos\WpfApp1\WpfApp1\MainWindow.xaml 40
    i got this error in the label inside the Grid, what is going on? GBU!

  • @a_bahar
    @a_bahar 4 роки тому +1

    I know you want to teach it simple and fast. But please use WPF features and technologies. Like binding, command, ...

  • @simplesource2457
    @simplesource2457 Рік тому

    Thanks so much this is so simple and clear

  • @ajones1274
    @ajones1274 6 років тому +2

    every time you click a button it creates a new instance of a page ? Thats not great, what if i hit that button 1000 times, i have a 1000 instances

    • @whatsupbudbud
      @whatsupbudbud 6 років тому

      Isn't C# automatically disposing of garbage?

    • @grassrootfilms
      @grassrootfilms 6 років тому +1

      @@whatsupbudbud I was wondering this myself and did a small test and it actually doesn't look like it does. If you keep opening the 2 pages again and again, your ram usage will continue to slightly increase. If you call a main.content=nothing, the page will disappear, but the GC still doesn't fire and the memory usage shows to be the same. Disappointing really.

    • @whatsupbudbud
      @whatsupbudbud 6 років тому

      @@grassrootfilms Very disappointing, indeed. Thanks for testing!

  • @csscoder9964
    @csscoder9964 4 роки тому

    Ohh thank you sooo much. This video is great. It helped me a lot😍💕

  • @laurencegr9978
    @laurencegr9978 4 роки тому

    Very helpful and concise.

  • @abcuuxyz
    @abcuuxyz 7 років тому

    I do not speak English, but I understand the code... thanks!!!!!!!!!!!!!!!!!

  • @henrykaiser9470
    @henrykaiser9470 2 роки тому

    Liebe geht raus

  • @michaelhaddad2190
    @michaelhaddad2190 8 років тому

    Awesome Tutorial. I do not know why it has so little views.

  • @OTadashi162
    @OTadashi162 5 років тому +2

    OMG, i can't believe it's so simple 🙀

  • @far-red
    @far-red 5 місяців тому

    that is exactly what i wanted to do, in web form is loading new form, in WFP i guess we load pages and not windows.
    thx

  • @zdillzz
    @zdillzz 8 років тому +1

    Thanks for the video! Helped me out loads.

  • @carmenmatisan6766
    @carmenmatisan6766 7 років тому

    how we can do this but using MVVM light toolkit?

  • @angamandu
    @angamandu 5 років тому +3

    This was super helpful, thank you!

  • @codewithkhattak4757
    @codewithkhattak4757 4 роки тому

    Very helpful, Thanks

  • @rickfuzzy
    @rickfuzzy 2 роки тому

    Excellent. Thank you

  • @nvv197827
    @nvv197827 3 роки тому

    How can i go back to the main page

  • @rabinsrai5078
    @rabinsrai5078 2 роки тому

    how tto add pageload event. as i want to show data on page load

  • @julianesteves41
    @julianesteves41 4 роки тому

    It's good but this create a new instance for each click, and it's convenient a hierarchical navigation structure in most cases. but, thanks!

  • @aleksandraarsic1100
    @aleksandraarsic1100 Рік тому

    Thank you good sir!

  • @danielgorgis2616
    @danielgorgis2616 6 років тому

    Excatly what i was looking for! thanks man

  • @fernandoarnaldovilanculo8286
    @fernandoarnaldovilanculo8286 2 роки тому

    Hero!

  • @Chefspatz
    @Chefspatz 2 роки тому

    I love it! Thanks! :)

  • @mobinabdolalipour2925
    @mobinabdolalipour2925 8 років тому +10

    Thank You Thank You Thank You. Helped me a lot

  • @DaveWatts_ejectamenta
    @DaveWatts_ejectamenta Рік тому

    Nice tutorial, you passed where Microsoft failed.

  • @pratapgowda498
    @pratapgowda498 Рік тому

    I am getting error Main.Content definition of content not found

  • @floadcope4039
    @floadcope4039 4 роки тому +1

    Thank you! This was really helpful.

  • @trieukhac8776
    @trieukhac8776 5 років тому +1

    Thank you. Love you so much for uploading this video :D

  • @deltavalley4020
    @deltavalley4020 Рік тому

    great stuff

  • @jakethe3z1kk59
    @jakethe3z1kk59 3 роки тому

    You just created 6 instances of pages its going to eat up a lot of cpu after a while. You should instead close the previous pages or return to the previous page

  • @mykolahureiev6466
    @mykolahureiev6466 2 роки тому

    perfect way to make a memory leaks

  • @whoman0385
    @whoman0385 2 роки тому

    You have saved my braincells thank you sir

  • @hwcdi6041
    @hwcdi6041 Рік тому

    Thank you bro it so usefull

  • @shmutalov
    @shmutalov 8 років тому +1

    Good tutor. Thank you

  • @RandomGamesRUS
    @RandomGamesRUS 6 років тому

    You are Best!!

  • @MooseKapoose
    @MooseKapoose 8 років тому

    He is our cs teacher

  • @symonxd
    @symonxd 4 роки тому

    Very informative, arigato

  • @louismastbooms5048
    @louismastbooms5048 4 роки тому

    nah if i type Main.content main becomes red and gives an error

    • @maccagaming935
      @maccagaming935 4 роки тому

      Double check the name if the frame within xaml view

  • @aleksandrastocka2304
    @aleksandrastocka2304 5 років тому

    Very helpful. Thank you! :)

  • @voidvary8854
    @voidvary8854 4 роки тому

    very helpful thanks!

  • @FCMTX
    @FCMTX 5 місяців тому

    W videoo

  • @sharif3694
    @sharif3694 4 роки тому

    Jij bent man

  • @bigdummyhead2162
    @bigdummyhead2162 4 роки тому

    Thank You!

  • @sealkeen
    @sealkeen 5 років тому

    Thank you, sir!

  • @pepperplume
    @pepperplume 8 років тому +1

    Nice vid, have a thumbs up

  • @yekohein1528
    @yekohein1528 3 роки тому

    Thank you sir.

  • @jeffstarkmann6381
    @jeffstarkmann6381 8 років тому

    Thank you, men !