Click here to Skip to main content
15,922,894 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: GridView displaying 2 columns with custom controls Pin
Gareth H20-Oct-10 23:08
Gareth H20-Oct-10 23:08 
AnswerRe: GridView displaying 2 columns with custom controls Pin
Gareth H21-Oct-10 6:12
Gareth H21-Oct-10 6:12 
QuestionHow to check if i'm in run-time or design time ? Pin
Yanshof20-Oct-10 3:03
Yanshof20-Oct-10 3:03 
AnswerRe: How to check if i'm in run-time or design time ? Pin
Gareth H20-Oct-10 3:53
Gareth H20-Oct-10 3:53 
QuestionHow to create a listview with multiple datatemplates Pin
Member 324168819-Oct-10 10:30
Member 324168819-Oct-10 10:30 
QuestionHow to change image\parameters on style definition ? Pin
Yanshof18-Oct-10 21:52
Yanshof18-Oct-10 21:52 
AnswerRe: How to change image\parameters on style definition ? Pin
Abhinav S19-Oct-10 3:55
Abhinav S19-Oct-10 3:55 
Questioncombo box items are not going up/down from keyboard arrow keys. Pin
SRKSHOME17-Oct-10 23:13
SRKSHOME17-Oct-10 23:13 
QuestionWPF MVVM design time data? Pin
SledgeHammer0117-Oct-10 19:42
SledgeHammer0117-Oct-10 19:42 
AnswerRe: WPF MVVM design time data? Pin
SledgeHammer0117-Oct-10 20:03
SledgeHammer0117-Oct-10 20:03 
QuestionA few newb MVVM (WPF) questions... Pin
SledgeHammer0117-Oct-10 16:53
SledgeHammer0117-Oct-10 16:53 
AnswerRe: A few newb MVVM (WPF) questions... Pin
Abhinav S17-Oct-10 18:17
Abhinav S17-Oct-10 18:17 
AnswerRe: A few newb MVVM (WPF) questions... Pin
Mycroft Holmes17-Oct-10 23:40
professionalMycroft Holmes17-Oct-10 23:40 
AnswerRe: A few newb MVVM (WPF) questions... Pin
Pete O'Hanlon18-Oct-10 0:32
mvePete O'Hanlon18-Oct-10 0:32 
GeneralRe: A few newb MVVM (WPF) questions... Pin
SledgeHammer0118-Oct-10 7:57
SledgeHammer0118-Oct-10 7:57 
GeneralRe: A few newb MVVM (WPF) questions... Pin
Pete O'Hanlon18-Oct-10 9:55
mvePete O'Hanlon18-Oct-10 9:55 
GeneralRe: A few newb MVVM (WPF) questions... Pin
SledgeHammer0118-Oct-10 10:37
SledgeHammer0118-Oct-10 10:37 
GeneralRe: A few newb MVVM (WPF) questions... Pin
Pete O'Hanlon19-Oct-10 2:18
mvePete O'Hanlon19-Oct-10 2:18 
AnswerRe: A few newb MVVM (WPF) questions... Pin
si61821-Oct-10 19:33
si61821-Oct-10 19:33 
AnswerRe: A few newb MVVM (WPF) questions... [SOLUTION] Pin
AndrewSmith22-Oct-10 17:08
AndrewSmith22-Oct-10 17:08 
I too often wondered about things like this. But I have finally come to terms that I think makes the most sense.

1) Go ahead and use the CurrentItem and force that behavior on the ViewModel. I think the hard fact is that ViewModels shouldn't be used across different presentation frameworks (e.g. WebForms, Asp.Net MVC, Windows Forms, WPF). This shouldn't happen for a multitude of reasons. The major point is your going to paint yourself into a very difficult and hard to use ViewModel to try and achieve compatibility with all of these frameworks. I have often fought with this too, and I came to some really good conclusions trying to learn the real way to treat ViewModels.

* ViewModels work best as an organizational structure. I treat ViewModels as an organization unit and not another technical layer of abstractions. This will give you optimal productivity and fewer bugs. With a well structured and organized ViewModel you create a more maintainable and agile product base. You shouldn't think about using ViewModels in "other" places than the one your creating it for, because it just doesn't work well.

* ViewModel code should be very simple. This means that the ViewModel code should be very simple that even a 2 year old can write them. Sure you can have a ViewModelBase class that contains some important infrastructure for your application, but after that your ViewModel code should be simple. With really simple viewmodel code, you can write up a ViewModel for exactly what you need in a few minutes.


Now, i know what some people are going to complain saying that they want to have a single ViewModel for everything. But with a focused and really simple to write ViewModels. It's painless to create more classes for your program to do exactly what you need.

Does this mean that your going to have a lot of ViewModels? YES.
Does this mean you have to write a ViewModel for Windows Forms and a different one for WPF? YES

If you think ViewModels should be another component of re-use, please take a look at this post from Udi about the fallacy of re-use.
http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/[^]




2) For the Commands, I like to use the RelayCommand implementation: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090030[^]

This is pretty much "The" way to handle code only ViewModels. This allows to have the behavior that your looking for.

<br />
public Person SelectedPerson { get; set; } // <-- this should be a dependency property or notify property to support two-way binding<br />
<br />
public ICommand EditCommand { get; private set; }<br />
<br />
private void OnEdit(object arg)<br />
{<br />
    //Edit the SelectedPerson<br />
}<br />
<br />
public SomeViewModel()<br />
{<br />
    EditCommand = new RelayCommand(OnEdit, x => SelectedPerson != null);<br />
}<br />



This works really well, and it's very simple too!
QuestionConnect silverlight project to web project. Pin
dbrenth15-Oct-10 10:55
dbrenth15-Oct-10 10:55 
AnswerRe: Connect silverlight project to web project. Pin
Abhinav S15-Oct-10 18:41
Abhinav S15-Oct-10 18:41 
QuestionDynamically instantiate UserControl, try to find which UserControl fired an event in an event Handler? Pin
Jean DUSUD14-Oct-10 11:38
Jean DUSUD14-Oct-10 11:38 
AnswerRe: Dynamically instantiate UserControl, try to find which UserControl fired an event in an event Handler? Pin
Abhinav S14-Oct-10 17:24
Abhinav S14-Oct-10 17:24 
AnswerRe: Dynamically instantiate UserControl, try to find which UserControl fired an event in an event Handler? Pin
#realJSOP15-Oct-10 9:04
professional#realJSOP15-Oct-10 9:04 

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.