Click here to Skip to main content
15,886,110 members
Home / Discussions / WPF
   

WPF

 
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 
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 
You are correct that there are better ways to do this. I was building off of your example... not following the cleanest way to do it. Plus, that is sort of a moving target. What you think may be the cleanest way to do it I may think isn't. So my goal was to show you one way of achieving what you wanted using the framework you had setup.

The driving factor for my example is that you have a sub-view which you put into the content of the grid in the main view. You create a view model for both the host (main) view and the sub-view. The key thing here is to understand that despite declaring the sub-view as a 'user control' it isn't a control in the traditional sense of the word. That is why DP implementation is a bad choice in this situation. In fact, I hate the "user control" terminology because I think it muddies the waters. They should have called is a "user view" instead but since the class inherits from Control I can understand the naming. So your demo had a main view and a sub view both with view models attached to them. In order to communicate between those two view models in a way that doesn't create a dependency between them requires a third party. That could be command classes, a static or singleton class (as I demonstrated), and a messaging facility. The specifics aren't as important as choosing what is right for your situation and avoiding a dependency between the view models.

Circling back around I think I'm understanding where you want to go with this and where we are missing the mark. I think you want the picker to be a CUSTOM CONTROL so you can put it on the main page and have access to the selected item as a property on that control. That is very different than the approach you took in the demo app. The architecture with the views and view models threw me.

A custom control actually has nothing to do with MVVM or view models but rather is a marriage of a code file that inherits from control and a xaml template that skins the control typically defined in /Themes/generic.xaml. In this case you can add properties and methods to the class to create the behaviors you want that control to have. That is the time to use dependency properties... but they go on the control class.

Custom controls aren't for the faint of heart. There are a number of required moving parts and some very specific requirements. I've got a three part article series that takes you from a blank project to a working custom control but it is still in draft status. I'll try to hurry up and get it published. It would be a good read for you if you want to tackle turning the picker into a custom control.
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 
QuestionWPF TreeView on a Windows 8 Tablet Pin
Kevin Marois3-Sep-13 6:56
professionalKevin Marois3-Sep-13 6:56 
AnswerRe: WPF TreeView on a Windows 8 Tablet Pin
Pete O'Hanlon3-Sep-13 10:12
mvePete O'Hanlon3-Sep-13 10:12 
GeneralRe: WPF TreeView on a Windows 8 Tablet Pin
Kevin Marois3-Sep-13 10:37
professionalKevin Marois3-Sep-13 10:37 
QuestionHow to avoid repeating dynamic tabitem at runtime? Pin
LAPEC2-Sep-13 15:07
LAPEC2-Sep-13 15:07 

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.