5 Replies - 558 Views - Last Post: 01 April 2013 - 06:46 PM Rate Topic: -----

#1 renz.bagaporo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 19-July 12

Problem with eventhandlers routedeventargs.

Posted 01 April 2013 - 04:16 AM

So in my program, I have two stackpanels. Let's call them stackpanel A and stackpanel B. Each stackpanel contains a number of LetterButtons, a class that I have created on my own that inherits from Windows.UI.Xaml.Controls.Button. The LetterButton objects are generated programatically.


As a result, I also have two eventhandlers, one for if a LetterButton that belongs to stackpanel A is clicked an one in B.

You can see them in this picture, guessLetterButton_Click and scrambledLettertButton_Click:

https://dl.dropbox.c...312/problem.png

The lines with the breakpoints are my question. For scrambledLettertButton_Click, line 119 seem to work fine.

But for line 105, it does not, as you can see in the Locals pane below. sButton contains '0' as the Letter property, whereas I think it shouldn't. I think it does not return the proper original source, as in line 119. Why is that?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with eventhandlers routedeventargs.

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,117
  • Joined: 05-May 12

Re: Problem with eventhandlers routedeventargs.

Posted 01 April 2013 - 05:32 AM

Can you please post the code (not a screenshot) that you use to populate each of the stackpanels? There isn't enough information in what you posted to answer "why is that"?

As an side, on first glance of your code, although you are using WPF, you are writing code for it as if it were WinForms. It's usually a sign that you aren't following the MVVM pattern if you are hooking up events to controls directly, instead of just depending on model property change events.
Was This Post Helpful? 0
  • +
  • -

#3 renz.bagaporo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 19-July 12

Re: Problem with eventhandlers routedeventargs.

Posted 01 April 2013 - 06:26 AM

No, I am not using the MVVM pattern as of the moment.

Here is the code by the way:
foreach (char c in currentGame.WordToGuess)
{
LetterButton guessLetterButton = new LetterButton("ms-appx:///Assets/LETTERS/Bullet.png", 10, 10, Stretch.Uniform) { Height = 50, Width = 50, IsEnabled = false };
guessLetterButton.Click += guessLetterButton_Click;
guessWord_stckpnl.Children.Add(guessLetterButton);
}


This post has been edited by Skydiver: 01 April 2013 - 03:06 PM
Reason for edit:: Put code within code tags.

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,117
  • Joined: 05-May 12

Re: Problem with eventhandlers routedeventargs.

Posted 01 April 2013 - 03:09 PM

That code doesn't set the Letter property of the LetterButton. I'm not seeing where the c is used. I must just be too tired to see it.
Was This Post Helpful? 0
  • +
  • -

#5 renz.bagaporo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 19-July 12

Re: Problem with eventhandlers routedeventargs.

Posted 01 April 2013 - 04:39 PM

Setting the Letter content is in some other part of the code.

I just noticed something:

https://dl.dropbox.c...15312/guess.png
https://dl.dropbox.c...2715312/scr.png

Notice that the desired property Letter's value is entrenched farther in guessWord_stckpnl than in scrambleWord_stckpnl. Could that be the problem?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3576
  • View blog
  • Posts: 11,117
  • Joined: 05-May 12

Re: Problem with eventhandlers routedeventargs.

Posted 01 April 2013 - 06:46 PM

So you have more than one LetterButton class?

Anyway, my gut feel is that you've take the wrong turn somewhere and are using your controls as storage for your model, rather than having a model, and letting the controls just render the state of the model. Let me highly recommend taking the time to switch over to MVVM pattern or an MVC pattern. WPF is really geared to work well with MVVM, why fight it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1