Click here to Skip to main content
15,305,969 members
Home / Discussions / WPF
   

WPF

 
QuestionProblems updating datagrid from collection Pin
abollmeyer23-Jan-14 10:55
Memberabollmeyer23-Jan-14 10:55 
AnswerRe: Problems updating datagrid from collection Pin
Mycroft Holmes23-Jan-14 12:04
professionalMycroft Holmes23-Jan-14 12:04 
QuestionBinding property from XML file data Pin
abollmeyer21-Jan-14 9:18
Memberabollmeyer21-Jan-14 9:18 
AnswerRe: Binding property from XML file data Pin
abollmeyer21-Jan-14 14:44
Memberabollmeyer21-Jan-14 14:44 
QuestionCombobox / Textblock field Pin
eddieangel21-Jan-14 6:24
Membereddieangel21-Jan-14 6:24 
AnswerRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 7:52
professionalJason Gleim21-Jan-14 7:52 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 8:07
Membereddieangel21-Jan-14 8:07 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 8:48
professionalJason Gleim21-Jan-14 8:48 
Assuming that your category object has members like "Id", "Name", "Description", etc I'm guessing that you want to change the Id via the combobox and have the rest of the properties follow suit. There are a couple of ways of doing it but knowing that it all starts with the property setter for Id is the key.

When the user selects an item in the combobox, it sets the SelectedItem property to the value or object you have specified. If it is a binding (as in your case) the setter gets called for that property. A normal setter, as you know, usually looks like:
C#
set
{
  if(_internalVar != value)
  {
    _internalVar = value;
    RaisePropertyChange("PropertyName");
  }
}


That works fine and raising property change there notifies any controls bound to that property that there is a change in it they should grab. But it doesn't do anything else. Even if you added a SelectedCategory property and bound that to the combobox then exposed name and ID through the internal variable, you still wouldn't fire the property change on the name property when the whole object was changed. That is because the binding system just isn't that smart. It must be told there is a change.

So you have a few options...

- If the combobox changes the ID, then in the setter for the ID property, change the name property as well. If you do it like Name = newValue then prop change gets raised in the setter for Name. If you use the internal variable like _name = newValue then you must follow that up by explicitly raising propertychanged passing Name as the property that has changed.

- You could expose just an ID property and in the setter call a method that sets the values on the category object. Again, if you use the public property setters you will get the event raised. If you use the internal versions, you must raise the event.


If you breakpoint on the Id property setter, property getter, and the same for the Name property, you will see how those things get called. (Basically setter followed by the getter in response to the event) To get the Name to update on the control, that PropertyChanged event needs to be raised carrying "Name" as the property name. How you get there is up to you.

Unfortunately, debugging bindings isn't always the easiest thing... in fact it can be pretty infuriating. A lot of times I'll break on those property setter/getter and start working backwards to figure out why something isn't working. And don't discount typos either. I can't tell you how many times a stupid typo when raising propertychanged or in a binding has wasted hours of my time.
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 9:14
Membereddieangel21-Jan-14 9:14 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 9:42
professionalJason Gleim21-Jan-14 9:42 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 10:12
Membereddieangel21-Jan-14 10:12 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 10:25
professionalJason Gleim21-Jan-14 10:25 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 11:29
Membereddieangel21-Jan-14 11:29 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim22-Jan-14 4:28
professionalJason Gleim22-Jan-14 4:28 
GeneralRe: Combobox / Textblock field Pin
eddieangel22-Jan-14 5:34
Membereddieangel22-Jan-14 5:34 
QuestionHow to stop repeating animation Pin
Member 1001614016-Jan-14 12:25
MemberMember 1001614016-Jan-14 12:25 
AnswerRe: How to stop repeating animation Pin
Varsha Ramnani20-Jan-14 22:41
professionalVarsha Ramnani20-Jan-14 22:41 
QuestionWPF Checkbox Binding Question Pin
Kevin Marois10-Jan-14 8:38
professionalKevin Marois10-Jan-14 8:38 
AnswerRe: WPF Checkbox Binding Question Pin
Meshack Musundi12-Jan-14 8:28
professionalMeshack Musundi12-Jan-14 8:28 
AnswerRe: WPF Checkbox Binding Question Pin
eddieangel21-Jan-14 7:53
Membereddieangel21-Jan-14 7:53 
QuestionVS2013: cannot locate resource Pin
Anthony.Canossi9-Jan-14 4:47
MemberAnthony.Canossi9-Jan-14 4:47 
AnswerRe: VS2013: cannot locate resource Pin
Mycroft Holmes9-Jan-14 11:49
professionalMycroft Holmes9-Jan-14 11:49 
GeneralRe: VS2013: cannot locate resource Pin
Anthony.Canossi9-Jan-14 21:25
MemberAnthony.Canossi9-Jan-14 21:25 
GeneralRe: VS2013: cannot locate resource Pin
Mycroft Holmes9-Jan-14 21:37
professionalMycroft Holmes9-Jan-14 21:37 
GeneralRe: VS2013: cannot locate resource Pin
Anthony.Canossi9-Jan-14 22:28
MemberAnthony.Canossi9-Jan-14 22:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.