Skip to main content
Home Forums Silverlight Programming Visual Studio & Silverlight Development Tools How to implement the INotifyPropertyChanged and ObservableCollection(of Of SoccerTeam) in my project ?
4 replies. Latest Post by Matthew R Hall on May 26, 2009.
(0)
barukaSi...
Member
0 points
2 Posts
02-04-2009 4:39 PM |
Here is my simple scenario: click to download the source code here http://67.199.20.148/soccer/SLSoccerScore.zip Here is the direct link to the live application http://flairfornow.com/SLSoccerScore/SLSoccerScore/bin/Debug/Default.html I am creating a silverlight 2 aplication to record a soccer game score : > TEAM A(Brazil) vs TEAM B (France). 2 buttons will trigger the incrementation of the score data value.(one click for one goal etc..) > the Class that define the data is quite simple as the following code below ( Featuring TeamName,Score and Coachname ) > Obviously the only value that will change during a soccer game will be the score value for each team. >The scores will be shown in 2 textlock controls ( TextblockScoreTeamA and TextblockScoreTeamB ) .in a datagrid > I designed a simple application with 2 buttons and 2 textblocks to begin with. >I created the code to define the related data class and properties as seen below. My problem is the folowing: I want to be able to update the value of the score data whenever a buton is clicked,and that new score value should show up on the textblock related to the team that make the goal.(click event attached to the buttons of course)I am wondering how to implement the INotifyPropertyChanged and ObservableCollection(of Of SoccerTeam) in this context ?? any clue ?? /////////////////////////////////////////////////////Partial Public Class Page Inherits UserControl
Here is my simple scenario:
click to download the source code here http://67.199.20.148/soccer/SLSoccerScore.zip
Here is the direct link to the live application
http://flairfornow.com/SLSoccerScore/SLSoccerScore/bin/Debug/Default.html
I am creating a silverlight 2 aplication to record a soccer game score :
> TEAM A(Brazil) vs TEAM B (France). 2 buttons will trigger the incrementation of the score data value.(one click for one goal etc..)
> the Class that define the data is quite simple as the following code below ( Featuring TeamName,Score and Coachname )
> Obviously the only value that will change during a soccer game will be the score value for each team.
>The scores will be shown in 2 textlock controls ( TextblockScoreTeamA and TextblockScoreTeamB ) .in a datagrid
> I designed a simple application with 2 buttons and 2 textblocks to begin with.
>I created the code to define the related data class and properties as seen below.
My problem is the folowing:
I want to be able to update the value of the score data whenever a buton is clicked,and that new score value should show up on the textblock related to the team that make the goal.(click event attached to the buttons of course)
any clue ??
/////////////////////////////////////////////////////
InitializeComponent()
grdDisplay.ItemsSource = SoccerTeamsList
End
_teamName= value
_score = value
Private
_coachName = value
//////////////////////////
Amanda W...
All-Star
17241 points
1,466 Posts
02-10-2009 4:50 AM |
Hi barukaSilver,
barukaSilver:click to download the source code here http://67.199.20.148/soccer/SLSoccerScore.zip
There is something wrong with the link.
barukaSilver:I am wondering how to implement the INotifyPropertyChanged and ObservableCollection(of Of SoccerTeam) in this context ??
You can try to refer these links to implement the INotifyPropertyChanged and ObservableCollection,
02-10-2009 11:54 AM |
Ok Folks ! May be I did n't explain correctely my issue here..
First of all look at the application I created at this link..
http://www.flairfornow.com/soccer/SLSoccerScore/SLSoccerScore/bin/Debug/Default.html
As you can see,any time you click on a button (ie France) the text box will update the nue value .Obvioulsly the binding is working fine.
How ever look closely in the field of the table ,the original values set( 0) are still there.I want to be able to
change (I should say Update) the value in the table field the same way it change in the text box.!!
The step would be:
Button clicked---> the text box show the new value---> the new value is updated in the the grid .
Conclusion next time I restart the application the recent valu should then be reflected in the grid !!
Hope I make myself clear.
Any hint ? Thank you in advance.
Here is the link for the code(zip)
http://flairfornow.com/soccer/SLSoccerScore.zip
nasiraziz
235 points
88 Posts
03-06-2009 1:51 AM |
ObservableCollection already implements the INotifyProperty change. Any binding object should reflect any changes to the ObservableCollection list. Are you sure your binding is done properly?
EDIT:
Ok, I was able to see your VB code also (NotePad duh). Your Binding in XAML seems fine. In your VB code I see that you are not using the ObservableCollection.
In your case, you need a collection of SoccerTeam Class, you need to do this (I dont know VB syntax well, here is the C# version, hope you can do the VB on it):ObservableCollection<SoccerTeam> soccerTeamList = new ObservableCollection<SoccerTeam> ();soccerTeamList.Add(new SoccerTeam { Value1 = "something", Value2 = "Something" });
You can change the values of the list by finding the item in collection and replacing its values:
var soccerTeam = (from s in soccerTeamList where s.TeamID = whatever select s).FirstOrDefault();soccerTeam.TeamScore = 10; //for example
This will reflect in the ObservableCollection and values will change in your grid. Hope this helps.
Matthew ...
12 points
6 Posts
05-26-2009 10:30 AM |
Its also useful to remember that its adding and removing objects to the observableCollection that raises the Notify event. If you modify the ObservableCollection in other ways (assigning one ObservableCollection to another) you'll want to raise the CollectionChanged event.