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. C#
  4. Adding extra parameters to events

Adding extra parameters to events

Scheduled Pinned Locked Moved C#
wpfdesignhelpquestion
16 Posts 7 Posters 3 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.
  • P paul_b 0

    I'll add a bit more of the code. The compositetransform is created along with one of the xaml components.

    public void NewButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
    {

    Canvas newcanvas = new Canvas();
    CompositeTransform mv = new CompositeTransform();
    AppGrid.Children.Add(newcanvas);

    Ellipse Holder = new Ellipse();
    Holder.ManipulationDelta += new ManipulationDeltaEventHandler(HolderManipulationDelta);

    }

    private void HolderManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e){ //code here}

    This code compiles, but I need to add the third parameter into the holdermanipulationdelta event, and when i do that i get the error message above.

    S Offline
    S Offline
    SledgeHammer01
    wrote on last edited by
    #7

    Why don't you make "mv" a class member? If you don't want to go that route for some "insane" :) reason, you can do what you want with lambdas:

    Canvas newcanvas = new Canvas();
    CompositeTransform mv = new CompositeTransform();

    AppGrid.Children.Add(newcanvas);

    Ellipse Holder = new Ellipse();

    Holder.ManipulationDelta += (x, y) =>
    {
    HolderManipulationData(x, y, mv);
    }

    That'll work, but I'd make it a class member since that's more "proper" IMO :).

    P 1 Reply Last reply
    0
    • S SledgeHammer01

      Why don't you make "mv" a class member? If you don't want to go that route for some "insane" :) reason, you can do what you want with lambdas:

      Canvas newcanvas = new Canvas();
      CompositeTransform mv = new CompositeTransform();

      AppGrid.Children.Add(newcanvas);

      Ellipse Holder = new Ellipse();

      Holder.ManipulationDelta += (x, y) =>
      {
      HolderManipulationData(x, y, mv);
      }

      That'll work, but I'd make it a class member since that's more "proper" IMO :).

      P Offline
      P Offline
      paul_b 0
      wrote on last edited by
      #8

      I'm fairly new to coding and was just trying to bodge it together quickly before figuring out the proper way to do it haha. Might sound a bit silly but it's the way I learn best. Thanks for your help I'll give that a go :)

      1 Reply Last reply
      0
      • L Liam Cairns Kelly

        You may want to look into using override. I can't find any tutorials that might help you and I'm not exactly an expert on the subject. But it might be worth while to search on your own as you'll know better what you need. Edit: The override function is used for changing things in classes and such, from what I can gather.

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

        There's nothing to override here. If you change the signature of a method, you are adding a new method, not overriding an existing one.

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        1 Reply Last reply
        0
        • P paul_b 0

          Okay so here's the deal. I have an event that generates a number of xaml components on the fly. One of these xaml components also has some events hooked up to it. In order to do this I am using the following line of code

          Holder.ManipulationDelta += new ManipulationDeltaEventHandler(HolderManipulationDelta);

          This is then handled with

          private void HolderManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e) {//code here }

          What I need is to be able to pass in an extra parameter in the event such as...

          private void HolderManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e, CompositeTransform mv) {//code here }

          However this seems to be invalid. I've tried googling and got some stuff on delegates etc but I cant get my head around it. Can anyone help me out?

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

          The standard convention in .NET for event delegates is to have just 2 parameters, the first is the object that generated the event and the second is a class derived from EventArgs that provides more information about the event. Note that this is not a hard and fast rule and you can have as many parameters as you like, but sticking to the convention makes your code cleaner, readable and maintainable. You can compose your CompositeTransform class inside ManipulationDeltaRoutedEventArgs as an instance field.

          E P 2 Replies Last reply
          0
          • P paul_b 0

            Okay so here's the deal. I have an event that generates a number of xaml components on the fly. One of these xaml components also has some events hooked up to it. In order to do this I am using the following line of code

            Holder.ManipulationDelta += new ManipulationDeltaEventHandler(HolderManipulationDelta);

            This is then handled with

            private void HolderManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e) {//code here }

            What I need is to be able to pass in an extra parameter in the event such as...

            private void HolderManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e, CompositeTransform mv) {//code here }

            However this seems to be invalid. I've tried googling and got some stuff on delegates etc but I cant get my head around it. Can anyone help me out?

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #11

            I consider SledgeHammer's response, using a Lambda, as the best, elegant solution (and I'm not competent in WPF/XAML), but I am curious, if you are defining a custom EventArgs class for use with your EventHandler: Why could you not add another parameter, of whatever 'mv's Type is, to that custom EventArgs class; then in your explicit EventHandler implementation which is "wired-up" to the Event, you can test if that instance of 'mv is null, and ignore, or, if not null: do whatever you want to do ? If this question is (and I fear it may be) way out-of-focus, I appreciate being corrected ! best, Bill

            "Everything we call real is made of things that cannot be regarded as real." Niels Bohr

            P S 2 Replies Last reply
            0
            • L Lost User

              The standard convention in .NET for event delegates is to have just 2 parameters, the first is the object that generated the event and the second is a class derived from EventArgs that provides more information about the event. Note that this is not a hard and fast rule and you can have as many parameters as you like, but sticking to the convention makes your code cleaner, readable and maintainable. You can compose your CompositeTransform class inside ManipulationDeltaRoutedEventArgs as an instance field.

              E Offline
              E Offline
              Ed Hill _5_
              wrote on last edited by
              #12

              This is a good solution (+5), however if the OP is working with the System.Windows.Shapes.Ellipse then they may need to look at overriding the OnManipulationDelta[^] Method so that they can use their extended ManipulationDeltaRoutedEventArgs.

              1 Reply Last reply
              0
              • B BillWoodruff

                I consider SledgeHammer's response, using a Lambda, as the best, elegant solution (and I'm not competent in WPF/XAML), but I am curious, if you are defining a custom EventArgs class for use with your EventHandler: Why could you not add another parameter, of whatever 'mv's Type is, to that custom EventArgs class; then in your explicit EventHandler implementation which is "wired-up" to the Event, you can test if that instance of 'mv is null, and ignore, or, if not null: do whatever you want to do ? If this question is (and I fear it may be) way out-of-focus, I appreciate being corrected ! best, Bill

                "Everything we call real is made of things that cannot be regarded as real." Niels Bohr

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

                This is actually a standard event argument for "the technology formerly known as Metro" style apps raised by the subsystem. It's not a custom one the user has created.

                *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                1 Reply Last reply
                0
                • L Lost User

                  The standard convention in .NET for event delegates is to have just 2 parameters, the first is the object that generated the event and the second is a class derived from EventArgs that provides more information about the event. Note that this is not a hard and fast rule and you can have as many parameters as you like, but sticking to the convention makes your code cleaner, readable and maintainable. You can compose your CompositeTransform class inside ManipulationDeltaRoutedEventArgs as an instance field.

                  P Offline
                  P Offline
                  paul_b 0
                  wrote on last edited by
                  #14

                  Cheers for your response. As I said I'm fairly new to this and I wasn't aware this was an option. I don't suppose you have a link to any good resources/tutorials on doing this so that I can read up on it?

                  L 1 Reply Last reply
                  0
                  • P paul_b 0

                    Cheers for your response. As I said I'm fairly new to this and I wasn't aware this was an option. I don't suppose you have a link to any good resources/tutorials on doing this so that I can read up on it?

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

                    Here[^] you go.

                    1 Reply Last reply
                    0
                    • B BillWoodruff

                      I consider SledgeHammer's response, using a Lambda, as the best, elegant solution (and I'm not competent in WPF/XAML), but I am curious, if you are defining a custom EventArgs class for use with your EventHandler: Why could you not add another parameter, of whatever 'mv's Type is, to that custom EventArgs class; then in your explicit EventHandler implementation which is "wired-up" to the Event, you can test if that instance of 'mv is null, and ignore, or, if not null: do whatever you want to do ? If this question is (and I fear it may be) way out-of-focus, I appreciate being corrected ! best, Bill

                      "Everything we call real is made of things that cannot be regarded as real." Niels Bohr

                      S Offline
                      S Offline
                      SledgeHammer01
                      wrote on last edited by
                      #16

                      Yeah, the lamba solution I provided was a "quick fix". I wouldn't do it that way in "professional" code. Making it a member was cleaner as noted. Unfortunately, I think OP is going down the entirely wrong path creating objects in code, but when you post those kind of responses on CodeProject, you tend to get 1 voted by people who "don't like your attitude", so I stopped bothering :). There is a danger with the lamba solution, that you could be passing an unintended instance of the wrong object if you don't pay attention :).

                      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