Click here to Skip to main content
15,885,216 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: No suitable axis is available for plotting the dependent value Pin
SunnyGaur23-Oct-13 17:07
SunnyGaur23-Oct-13 17:07 
Questionany chance to get expression gallery website content Pin
amigoface19-Oct-13 6:19
amigoface19-Oct-13 6:19 
AnswerRe: any chance to get expression gallery website content Pin
Richard Deeming21-Oct-13 3:15
mveRichard Deeming21-Oct-13 3:15 
QuestionSetting the value of TimePicker resets the DatePicker value, how can i solve thi Pin
rizwanahmed2417-Oct-13 11:28
rizwanahmed2417-Oct-13 11:28 
AnswerRe: Setting the value of TimePicker resets the DatePicker value, how can i solve thi Pin
Matt T Heffron17-Oct-13 15:03
professionalMatt T Heffron17-Oct-13 15:03 
GeneralRe: Setting the value of TimePicker resets the DatePicker value, how can i solve thi Pin
rizwanahmed2419-Oct-13 10:13
rizwanahmed2419-Oct-13 10:13 
QuestionWPF View Data Template Questions Pin
Kevin Marois17-Oct-13 9:41
professionalKevin Marois17-Oct-13 9:41 
AnswerRe: WPF View Data Template Questions Pin
SledgeHammer0117-Oct-13 17:00
SledgeHammer0117-Oct-13 17:00 
You are doing it bass akwards IMO Smile | :)

Remember, one of the mantras of MVVM is that the VM knows nothing about the view. The view obviously knows about the VM its rendering. If you setting up DataTemplates as you have, you are implying that you are creating a VM first and then assigning it a view based on the data type. This is implying that in some VM, you are newing up other random VMs (BAD -- VMs should not know about each other) and making "random decisions" for the VM / View relationship (also BAD).

What makes more sense (to me at least lol) is that as a command handler, I want to load a particular view. That view should then know what VM it needs and new it up and wire everything up. As I said in the paragraph above, if I am newing up VMs in code, I have to also new up the window, set the DataContext, etc. This is too much intimate knowledge.

What I like to do is just say "I want this particular view to popup":

Window logonWindow = LoadComponent(new Uri("Views/LogonWindow.xaml", UriKind.RelativeOrAbsolute)) as Window;

logonWindow.ShowDialog(); // or .Show() or whatever...

using ViewLocator & DI, Views/LogonWindow.xaml will automatically new up the appropriate VM, set the DataContext, call InitializeComponent(), etc.

In answer to your other question... if you have different look & feel, you might break out the two look & feels into two different templates then have a tiny "loader template"... the loader template would just use a DataTrigger to swap out to the other template if needed.

So your loader template will by default apply the PC Template and if your global/static IsTablet DP == true, it will apply the Tablet Template instead.

This is how custom controls are generally written. You have two styles for example: an XP style and an Aero style. Apply the XP style by default and then swap out for the Aero template if IsAero == true.


POH... if you are reading this... wouldn't mind hearing your comments on this approach. To me, this makes more sense then going the other way...
GeneralRe: WPF View Data Template Questions Pin
Pete O'Hanlon17-Oct-13 21:40
mvePete O'Hanlon17-Oct-13 21:40 
GeneralRe: WPF View Data Template Questions Pin
_Maxxx_21-Oct-13 19:49
professional_Maxxx_21-Oct-13 19:49 
GeneralRe: WPF View Data Template Questions Pin
SledgeHammer0122-Oct-13 7:27
SledgeHammer0122-Oct-13 7:27 
GeneralRe: WPF View Data Template Questions Pin
Mycroft Holmes22-Oct-13 12:49
professionalMycroft Holmes22-Oct-13 12:49 
GeneralRe: WPF View Data Template Questions Pin
_Maxxx_22-Oct-13 13:08
professional_Maxxx_22-Oct-13 13:08 
GeneralRe: WPF View Data Template Questions Pin
Mycroft Holmes22-Oct-13 14:13
professionalMycroft Holmes22-Oct-13 14:13 
GeneralRe: WPF View Data Template Questions Pin
SledgeHammer0122-Oct-13 14:46
SledgeHammer0122-Oct-13 14:46 
GeneralRe: WPF View Data Template Questions Pin
SledgeHammer0122-Oct-13 14:40
SledgeHammer0122-Oct-13 14:40 
GeneralRe: WPF View Data Template Questions Pin
_Maxxx_22-Oct-13 13:03
professional_Maxxx_22-Oct-13 13:03 
AnswerRe: WPF View Data Template Questions Pin
Gabriel Szabo17-Oct-13 23:03
Gabriel Szabo17-Oct-13 23:03 
GeneralRe: WPF View Data Template Questions Pin
SledgeHammer0118-Oct-13 4:54
SledgeHammer0118-Oct-13 4:54 
GeneralRe: WPF View Data Template Questions Pin
Gabriel Szabo21-Oct-13 22:35
Gabriel Szabo21-Oct-13 22:35 
GeneralRe: WPF View Data Template Questions Pin
SledgeHammer0122-Oct-13 5:21
SledgeHammer0122-Oct-13 5:21 
QuestionBinding to a collection in code behind Pin
Alessandro Ranieri17-Oct-13 3:24
Alessandro Ranieri17-Oct-13 3:24 
AnswerRe: Binding to a collection in code behind Pin
Matt T Heffron17-Oct-13 7:43
professionalMatt T Heffron17-Oct-13 7:43 
AnswerRe: Binding to a collection in code behind Pin
SledgeHammer0117-Oct-13 9:17
SledgeHammer0117-Oct-13 9:17 
AnswerRe: Binding to a collection in code behind Pin
Abhinav S17-Oct-13 17:12
Abhinav S17-Oct-13 17:12 

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.