Click here to Skip to main content
15,892,697 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Another DependencyProperty Question Pin
SledgeHammer016-Sep-13 5:07
SledgeHammer016-Sep-13 5:07 
GeneralRe: Another DependencyProperty Question Pin
Jason Gleim6-Sep-13 5:23
professionalJason Gleim6-Sep-13 5:23 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois6-Sep-13 6:59
professionalKevin Marois6-Sep-13 6:59 
GeneralRe: Another DependencyProperty Question Pin
Jason Gleim6-Sep-13 7:28
professionalJason Gleim6-Sep-13 7:28 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois6-Sep-13 7:54
professionalKevin Marois6-Sep-13 7:54 
GeneralRe: Another DependencyProperty Question Pin
Jason Gleim6-Sep-13 9:03
professionalJason Gleim6-Sep-13 9:03 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois6-Sep-13 9:40
professionalKevin Marois6-Sep-13 9:40 
GeneralRe: Another DependencyProperty Question Pin
Jason Gleim6-Sep-13 10:39
professionalJason Gleim6-Sep-13 10:39 
I fixed up your app to add a singleton class that will hold the currently selected client. Download it here[^].

You will see that in the classes folder I added a new class. It implements the singleton pattern and has a single property... SingletonClient. In the main view model and the client view model, I changed the SelectedClient property to use the new SingletonClient property of the new singleton class. In this way we are using a third-party class (with a single instance) to hold the currently selected client. Since we are doing this, we break the automatic binding support between the VM and the control. This is because the control will bind to the instance of the selected client rather than to the property itself. The fix is easy, we simply hook the PropertyChanged event on the singleton class from each view model that uses it. Inside that handler we check to see if the property that was changed is the one we are interested in. If it is, we manually raise PropertyChanged for the desired property on EACH viewmodel so the controls in each view get notified.

I added the same property to the MainViewViewModel and created a text block on the main view that will show you the name of the client that is currently selected. I also declared the main view model in xaml so you can see how to do that rather than in the code behind. Smile | :)

You will see that the text block at the top of the main view is bound to the selected client property on the main view model and uses the path to get the name and display it. You will also see that your client view is untouched illustrating how we can keep things separated yet still pass information via a third-party that both view models agree on.

If you were unit testing this, you would simply mock the singleton class allowing you to still test each viewmodel in isolation.
GeneralRe: Another DependencyProperty Question Pin
Jason Gleim6-Sep-13 10:53
professionalJason Gleim6-Sep-13 10:53 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois6-Sep-13 13:01
professionalKevin Marois6-Sep-13 13:01 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois9-Sep-13 7:12
professionalKevin Marois9-Sep-13 7:12 
GeneralRe: Another DependencyProperty Question Pin
Jason Gleim9-Sep-13 7:55
professionalJason Gleim9-Sep-13 7:55 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois9-Sep-13 8:01
professionalKevin Marois9-Sep-13 8:01 
GeneralRe: Another DependencyProperty Question Pin
Kevin Marois6-Sep-13 8:22
professionalKevin Marois6-Sep-13 8:22 
GeneralRe: Another DependencyProperty Question Pin
Pete O'Hanlon6-Sep-13 6:06
mvePete O'Hanlon6-Sep-13 6:06 
AnswerRe: Another DependencyProperty Question Pin
Richard Deeming6-Sep-13 4:22
mveRichard Deeming6-Sep-13 4:22 
GeneralRe: Another DependencyProperty Question Pin
SledgeHammer016-Sep-13 5:08
SledgeHammer016-Sep-13 5:08 
Questionneed a coah for a WPF projet Pin
vanjier4-Sep-13 6:17
vanjier4-Sep-13 6:17 
AnswerRe: need a coah for a WPF projet Pin
Pete O'Hanlon4-Sep-13 6:31
mvePete O'Hanlon4-Sep-13 6:31 
GeneralRe: need a coah for a WPF projet Pin
vanjier16-Sep-13 1:31
vanjier16-Sep-13 1:31 
GeneralRe: need a coah for a WPF projet Pin
Pete O'Hanlon16-Sep-13 1:50
mvePete O'Hanlon16-Sep-13 1:50 
AnswerRe: need a coah for a WPF projet Pin
Abhinav S9-Sep-13 7:15
Abhinav S9-Sep-13 7:15 
QuestionVirtual classroom using silverlight Pin
Member 101834574-Sep-13 1:22
Member 101834574-Sep-13 1:22 
GeneralRe: Virtual classroom using silverlight Pin
Richard MacCutchan4-Sep-13 5:04
mveRichard MacCutchan4-Sep-13 5:04 
AnswerRe: Virtual classroom using silverlight Pin
Pete O'Hanlon4-Sep-13 5:45
mvePete O'Hanlon4-Sep-13 5:45 

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.