Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Dumb Button Question alert!

Dumb Button Question alert!

Scheduled Pinned Locked Moved WPF
questioncsharpvisual-studiowpfhelp
15 Posts 3 Posters 37 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jammer 0

    Thanks for this Karl. Loads more learning to do now! Not sure I even know how to cast something at the moment. I'm still at the stage where I expect to be able do things that are simply daft, you shouldn't do or can't do at all. hmm ...

    Jammer Going where everyone here has gone before! :) My Blog

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #6

    What language to you use? C# or VB.NET?

    Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

    Just a grain of sand on the worlds beaches.

    J 1 Reply Last reply
    0
    • L Lost User

      What language to you use? C# or VB.NET?

      Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

      Just a grain of sand on the worlds beaches.

      J Offline
      J Offline
      Jammer 0
      wrote on last edited by
      #7

      C# all the way ... I'm just trying this but it doesn't work yet ...

      public sealed class ApplicationViewEventArgs : EventArgs
      {
          private Enums.ApplicationView \_applicationView;
      
          public Enums.ApplicationView ApplicationViewStatus
          {
              get
              {
                  return \_applicationView;
              }
          }
      
          public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus)
          {
              \_applicationView = ApplicationViewStatus;
          }
      }
      
      /// /// Interaction logic for Navigator.xaml
      /// 
      public partial class Navigator : UserControl
      {
          public delegate void ApplicationViewChanged(object sender, ApplicationViewEventArgs e);
      
          public event ApplicationViewChanged ApplicationViewStatusChanged;
      
          public Navigator()
          {
              InitializeComponent();
          }
      
          private void btnBrowseView\_Click(object sender, RoutedEventArgs e)
          {
              if (ApplicationViewStatusChanged != null)
      
                  ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.BrowserView));
      
          }
      
          private void btnDatabaseView\_Click(object sender, RoutedEventArgs e)
          {
              if (ApplicationViewStatusChanged != null)
      
                  ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.DataBaseView));
      
          }
      }
      

      with this in my main window:

          private void Navigator\_ApplicationViewStatusChanged(object o, ApplicationViewEventArgs e)
          {
              lyrBrowserView.Visibility = Visibility.Hidden;
              lyrDatabaseView.Visibility = Visibility.Hidden;
      
              switch (e.ApplicationViewStatus)
              {
                  case Enums.ApplicationView.BrowserView:
                      lyrBrowserView.Visibility = Visibility.Visible;
                      break;
                  case Enums.ApplicationView.DataBaseView:
                      lyrDatabaseView.Visibility = Visibility.Visible;
                      break;
              }
          }
      

      the Enums look like:

      public static class Enums
      {
          public enum ApplicationView
          {
              BrowserView = 0,
              DataBaseView = 1,
              ConfigurationView = 2
          }
      }
      

      This is the first time I've even delt with events! Not going well ... :(

      Jammer Going where ev

      L 1 Reply Last reply
      0
      • J Jammer 0

        C# all the way ... I'm just trying this but it doesn't work yet ...

        public sealed class ApplicationViewEventArgs : EventArgs
        {
            private Enums.ApplicationView \_applicationView;
        
            public Enums.ApplicationView ApplicationViewStatus
            {
                get
                {
                    return \_applicationView;
                }
            }
        
            public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus)
            {
                \_applicationView = ApplicationViewStatus;
            }
        }
        
        /// /// Interaction logic for Navigator.xaml
        /// 
        public partial class Navigator : UserControl
        {
            public delegate void ApplicationViewChanged(object sender, ApplicationViewEventArgs e);
        
            public event ApplicationViewChanged ApplicationViewStatusChanged;
        
            public Navigator()
            {
                InitializeComponent();
            }
        
            private void btnBrowseView\_Click(object sender, RoutedEventArgs e)
            {
                if (ApplicationViewStatusChanged != null)
        
                    ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.BrowserView));
        
            }
        
            private void btnDatabaseView\_Click(object sender, RoutedEventArgs e)
            {
                if (ApplicationViewStatusChanged != null)
        
                    ApplicationViewStatusChanged(this, new ApplicationViewEventArgs(Enums.ApplicationView.DataBaseView));
        
            }
        }
        

        with this in my main window:

            private void Navigator\_ApplicationViewStatusChanged(object o, ApplicationViewEventArgs e)
            {
                lyrBrowserView.Visibility = Visibility.Hidden;
                lyrDatabaseView.Visibility = Visibility.Hidden;
        
                switch (e.ApplicationViewStatus)
                {
                    case Enums.ApplicationView.BrowserView:
                        lyrBrowserView.Visibility = Visibility.Visible;
                        break;
                    case Enums.ApplicationView.DataBaseView:
                        lyrDatabaseView.Visibility = Visibility.Visible;
                        break;
                }
            }
        

        the Enums look like:

        public static class Enums
        {
            public enum ApplicationView
            {
                BrowserView = 0,
                DataBaseView = 1,
                ConfigurationView = 2
            }
        }
        

        This is the first time I've even delt with events! Not going well ... :(

        Jammer Going where ev

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #8

        I'm going to just spit out questions and comments, not in any order. If you are swapping which user control is displayed, would a TabControl work better for you? Is there a reason to put the buttons in a user control rather than just on the main form? If you're using an event, you should use a RoutedEvent rather than a regular event in WPF. This way the child objects can bubble the event up the ElementTree. Would a menu work for selection purposes? There is another way to accomplish this also. You can use buttons in your user control that use RoutedCommands. In the button CommandParamenter load the ApplicationView enum value for that button. Then, set up a listener called CommandBinding in the main window. You can use one of the RoutedCommands supplied with WPF or create your own. There are many articles on RoutedCommands here on Code Project. Suggest reading up on these. They enable decoupling of the command and the handler. I also recently posted this on my blog: http://karlshifflett.wordpress.com/2008/02/24/wpf-sample-series-wpf-mvc-tabcontrol-mdi-and-commandbindings/[^]

        Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

        Just a grain of sand on the worlds beaches.

        J 1 Reply Last reply
        0
        • L Lost User

          I'm going to just spit out questions and comments, not in any order. If you are swapping which user control is displayed, would a TabControl work better for you? Is there a reason to put the buttons in a user control rather than just on the main form? If you're using an event, you should use a RoutedEvent rather than a regular event in WPF. This way the child objects can bubble the event up the ElementTree. Would a menu work for selection purposes? There is another way to accomplish this also. You can use buttons in your user control that use RoutedCommands. In the button CommandParamenter load the ApplicationView enum value for that button. Then, set up a listener called CommandBinding in the main window. You can use one of the RoutedCommands supplied with WPF or create your own. There are many articles on RoutedCommands here on Code Project. Suggest reading up on these. They enable decoupling of the command and the handler. I also recently posted this on my blog: http://karlshifflett.wordpress.com/2008/02/24/wpf-sample-series-wpf-mvc-tabcontrol-mdi-and-commandbindings/[^]

          Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

          Just a grain of sand on the worlds beaches.

          J Offline
          J Offline
          Jammer 0
          wrote on last edited by
          #9

          I suppose any of those things are doable. I'm just swapping layers (or rather trying to swap layer visibility) I just wanted to put them in a user control in order to keep things tidy and it should be simple. There is something i'm just totally missing in the code I posted. I like buttons more than menus too :) Do you know why this isn't working?

          public sealed class ApplicationViewEventArgs : EventArgs
          {
              private Enums.ApplicationView \_applicationView;
          
              public Enums.ApplicationView ApplicationViewStatus
              {
                  get
                  {
                      return \_applicationView;
                  }
              }
          
              public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus) : base()
              {
                  \_applicationView = ApplicationViewStatus;
              }
          }
          

          this is obviously the whole deal but its always returning null ... is there a "using System.blah" for events that I should be using?

          Jammer Going where everyone here has gone before! :) My Blog

          L 1 Reply Last reply
          0
          • J Jammer 0

            I suppose any of those things are doable. I'm just swapping layers (or rather trying to swap layer visibility) I just wanted to put them in a user control in order to keep things tidy and it should be simple. There is something i'm just totally missing in the code I posted. I like buttons more than menus too :) Do you know why this isn't working?

            public sealed class ApplicationViewEventArgs : EventArgs
            {
                private Enums.ApplicationView \_applicationView;
            
                public Enums.ApplicationView ApplicationViewStatus
                {
                    get
                    {
                        return \_applicationView;
                    }
                }
            
                public ApplicationViewEventArgs(Enums.ApplicationView ApplicationViewStatus) : base()
                {
                    \_applicationView = ApplicationViewStatus;
                }
            }
            

            this is obviously the whole deal but its always returning null ... is there a "using System.blah" for events that I should be using?

            Jammer Going where everyone here has gone before! :) My Blog

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #10

            I don't see anything wrong, but my strength is VB.NET. Maybe Pete can look at this for you.

            Jammer wrote:

            this is obviously the whole deal but its always returning null

            Not sure why these event args are null. Did you set up an event handler for them in the main form? Since you are new to WPF, you may want to take a step back and read up on RoutedCommands. This is the best solution for these buttons.

            Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

            Just a grain of sand on the worlds beaches.

            J 1 Reply Last reply
            0
            • L Lost User

              I don't see anything wrong, but my strength is VB.NET. Maybe Pete can look at this for you.

              Jammer wrote:

              this is obviously the whole deal but its always returning null

              Not sure why these event args are null. Did you set up an event handler for them in the main form? Since you are new to WPF, you may want to take a step back and read up on RoutedCommands. This is the best solution for these buttons.

              Cheers, Karl » CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your Articles

              Just a grain of sand on the worlds beaches.

              J Offline
              J Offline
              Jammer 0
              wrote on last edited by
              #11

              Hi Karl, Thanks for that ... its weird isn't it ... i'm going backwards and forwards with this code and its just never getting evaluated and never grabbing the enums ... I have this in the main form that never gets called due to the if{} always being null ...

                  private void Navigator\_ApplicationViewStatusChanged(object o, ApplicationViewEventArgs e)
                  {
                      lyrBrowserView.Visibility = Visibility.Hidden;
                      lyrDatabaseView.Visibility = Visibility.Hidden;
              
                      switch (e.ApplicationViewStatus)
                      {
                          case Enums.ApplicationView.BrowserView:
                              lyrBrowserView.Visibility = Visibility.Visible;
                              break;
                          case Enums.ApplicationView.DataBaseView:
                              lyrDatabaseView.Visibility = Visibility.Visible;
                              break;
                      }
                  }
              

              I can't see anything i'm doing differently to any of the examples I'm finding online. I'm going to take a look at RoutedCommands I think. This is doing my head in ... Thanks chap. Pete, if you can shed any light on this I'll be forever in your debt!

              Jammer Going where everyone here has gone before! :) My Blog

              P 1 Reply Last reply
              0
              • J Jammer 0

                Hi Karl, Thanks for that ... its weird isn't it ... i'm going backwards and forwards with this code and its just never getting evaluated and never grabbing the enums ... I have this in the main form that never gets called due to the if{} always being null ...

                    private void Navigator\_ApplicationViewStatusChanged(object o, ApplicationViewEventArgs e)
                    {
                        lyrBrowserView.Visibility = Visibility.Hidden;
                        lyrDatabaseView.Visibility = Visibility.Hidden;
                
                        switch (e.ApplicationViewStatus)
                        {
                            case Enums.ApplicationView.BrowserView:
                                lyrBrowserView.Visibility = Visibility.Visible;
                                break;
                            case Enums.ApplicationView.DataBaseView:
                                lyrDatabaseView.Visibility = Visibility.Visible;
                                break;
                        }
                    }
                

                I can't see anything i'm doing differently to any of the examples I'm finding online. I'm going to take a look at RoutedCommands I think. This is doing my head in ... Thanks chap. Pete, if you can shed any light on this I'll be forever in your debt!

                Jammer Going where everyone here has gone before! :) My Blog

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #12

                Jammer - sorry that it's taken so long for me to get to this. It's the first time I've been online in a couple of days. Have you actually hooked the event up to anything in the main form? If you want to send me the project (zipped up of course), I'll be more than happy to take a look at it.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                J 1 Reply Last reply
                0
                • P Pete OHanlon

                  Jammer - sorry that it's taken so long for me to get to this. It's the first time I've been online in a couple of days. Have you actually hooked the event up to anything in the main form? If you want to send me the project (zipped up of course), I'll be more than happy to take a look at it.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  J Offline
                  J Offline
                  Jammer 0
                  wrote on last edited by
                  #13

                  Hey Pete, Wow, that is an incredibly nice offer. I actually persisted and got my code working after some more head scratching. I was being extremely daft! I had given my user control an x:Name="" but only in the controls XAML file, not the main window XAML file where it is actually being instantiated. As soon as I'd done that all was well. I'm just looking at some other UI code at the moment. I'm just in the process of building some new buttons and implementing some RoutedCommands. Been quite a successful day of coding so far. I've practically finished a lot of the UI styling (using Blend) and I've implemented my first object serialization exercise ... bloody code worked first test! So my database is now persisted on disk! wooo ... I'm loving C# ... XAML is still a tad confusing though.

                  Jammer Going where everyone here has gone before! :) My Blog

                  P 1 Reply Last reply
                  0
                  • J Jammer 0

                    Hey Pete, Wow, that is an incredibly nice offer. I actually persisted and got my code working after some more head scratching. I was being extremely daft! I had given my user control an x:Name="" but only in the controls XAML file, not the main window XAML file where it is actually being instantiated. As soon as I'd done that all was well. I'm just looking at some other UI code at the moment. I'm just in the process of building some new buttons and implementing some RoutedCommands. Been quite a successful day of coding so far. I've practically finished a lot of the UI styling (using Blend) and I've implemented my first object serialization exercise ... bloody code worked first test! So my database is now persisted on disk! wooo ... I'm loving C# ... XAML is still a tad confusing though.

                    Jammer Going where everyone here has gone before! :) My Blog

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #14

                    That's excellent. Sorry I couldn't get back to you earlier on this.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    J 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      That's excellent. Sorry I couldn't get back to you earlier on this.

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      J Offline
                      J Offline
                      Jammer 0
                      wrote on last edited by
                      #15

                      Not at all chap. You've been a great help!

                      Jammer Going where everyone here has gone before! :) My Blog

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups