Click here to Skip to main content
15,891,629 members
Home / Discussions / WPF
   

WPF

 
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 
Say I have a dialog with a list box and 3 buttons: Add, Edit and Delete. The listbox displays a list of Widget objects.

I'm assuming the "proper MVVM way" is to do something like:

class ViewModel
{
public ObservableCollection<widget> Widgets { ... };
public Command AddCommand { ... };
public Command EditCommand { ... };
public Command DeleteCommand { ... };
}

Add then the ListBox.ItemsSource binds to Widgets, the Add button to AddCommand, Edit to EditCommand and so on...

Now is where I get confused on MVVM...

1) Typical Add button behavior is to auto select the new item. How would that happen? It was suggested to me that ViewModel expose a "CurrentItem" property for **2-way** data binding with the listbox. The AddCommand handler would update the CurrentItem after it creates it. Is this a good idea? To me, that seems hokey as it would force that behavior on everybody using the view model. Also, it would set that property in situations where it may not want to be set. Any ideas?

2) Obviously, Edit and Delete need to be disabled if no item is selected. I know how to do that the "non MVVM" way, but what is the MVVM way? I know the command has a CanExecute handler. Should all that logic happen in there? It would seem I would either need the list box or the selected item and the collection.

I guess I'm just trying to figure out where the line should be drawn at which code goes in the code behind and which goes in the view model.

I understand MVVM "purists" say ZERO code in the code behind, but it seems to me like you'll be creating a lot of properties, commands, etc and jumping through a lot of hoops to have all the bindable properties in the view model.
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 
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
mve#realJSOP15-Oct-10 9:04 
GeneralRe: Dynamically instantiate UserControl, try to find which UserControl fired an event in an event Handler? Pin
Jean DUSUD18-Oct-10 11:00
Jean DUSUD18-Oct-10 11:00 
QuestionDataGrid SelectionChanged event is firing only on first row selected. Pin
Member 392066714-Oct-10 4:56
Member 392066714-Oct-10 4:56 
AnswerRe: DataGrid SelectionChanged event is firing only on first row selected. Pin
torken214-Oct-10 20:37
professionaltorken214-Oct-10 20:37 

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.