Click here to Skip to main content
15,917,176 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF TabControl Events Pin
Tom Delany10-Jan-12 10:15
Tom Delany10-Jan-12 10:15 
GeneralRe: WPF TabControl Events Pin
Pete O'Hanlon10-Jan-12 10:29
mvePete O'Hanlon10-Jan-12 10:29 
GeneralRe: WPF TabControl Events Pin
Tom Delany10-Jan-12 10:35
Tom Delany10-Jan-12 10:35 
GeneralRe: WPF TabControl Events Pin
Tom Delany10-Jan-12 10:17
Tom Delany10-Jan-12 10:17 
GeneralRe: WPF TabControl Events Pin
Pete O'Hanlon10-Jan-12 10:32
mvePete O'Hanlon10-Jan-12 10:32 
GeneralRe: WPF TabControl Events Pin
Tom Delany10-Jan-12 10:37
Tom Delany10-Jan-12 10:37 
GeneralRe: WPF TabControl Events Pin
Pete O'Hanlon10-Jan-12 10:38
mvePete O'Hanlon10-Jan-12 10:38 
GeneralRe: WPF TabControl Events [Edited] Pin
Tom Delany10-Jan-12 11:34
Tom Delany10-Jan-12 11:34 
Collin,

I've been mulling over your post. It has brought more questions to mind. (Sorry. Blush | :O ) Let me preface what follows with: If I ask something really obvious or stupid, please forgive me. I have been programming for quite a few years, but I am a WPF neophyte. Ditto, if I use the wrong terminology for something. I'm not a GUI programmer ( D'Oh! | :doh: ), but I am the only PC programmer in our group, and have been forced to jump into this with both feet. I don't really mind as I like to learn new things, but the WPF / MVVM learning curve has been frustrating for me. Sigh | :sigh:

Collin Jasnoch wrote:
If you had a MainViewModel then the TabControl could have its ItemSource bound to a collection of your viewmodels (the data contexts of the Tabs).

The Tab Control can also maintain binding of "SelectedItem". When it changes you could then run any logic you wanted to (prompt user to save etc.)

That sounds very sensible to me. Obviously (?) my ViewModels are not exactly the same. I guess I should find what is common among them and turn that into a base class (yeah, I should have done that from the outset) that they are all derived from, so that I can create an ObservableCollection of the base class objects? Since the ItemSource is bound to the ObservableCollection, this would take care of setting the DataContext for each TabItem?

Collin Jasnoch wrote:
If you choose this path, rather than having the View instantiate the VM*, the MainVM does the work. Then you just need to tell the renderer how to render the object using DataTemplates.

Right now, each TabItem in my TabControl is populated with a separate (but very similar) UserControl that consists of a 3 column Grid with a ListBox in column 0, a GridSplitter in column 1, and another Grid in Column 2. The second Grid in column 2 is a 3 row Grid with the first row containing a TextBlock that is basically a header, the 2nd row containing various TextBlocks and TextBoxes for displaying/entering data, and the last row holding several Buttons. Clicking on an item in the ListBox on the left brings up the corresponding data in the fields on the right.

How would I turn this into a DataTemplate? What about the buttons?

Collin Jasnoch wrote:
I prefer this method (VM before View*) as it seems cleaner to me (no code behind)

Dumb question: isn't a certain amount of code behind unavoidable? Like for Button Click and other event handlers? I have been trying to keep what I do there to a bare minimum (i.e. the event handlers simply call "Action" methods in the ViewModel class), but I have found no way to completely eliminate it.

Thanks for your help. Sorry again about the stupid questions. Blush | :O
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.

There are 10 kinds of people in the world: People who know binary and people who don't.

GeneralRe: WPF TabControl Events [Edited] Pin
Mycroft Holmes10-Jan-12 13:11
professionalMycroft Holmes10-Jan-12 13:11 
GeneralRe: WPF TabControl Events Pin
Tom Delany10-Jan-12 14:08
Tom Delany10-Jan-12 14:08 
GeneralRe: WPF TabControl Events Pin
Tom Delany11-Jan-12 3:40
Tom Delany11-Jan-12 3:40 
GeneralRe: WPF TabControl Events Pin
Tom Delany12-Jan-12 7:53
Tom Delany12-Jan-12 7:53 
GeneralRe: WPF TabControl Events [Edited] Pin
Tom Delany11-Jan-12 8:32
Tom Delany11-Jan-12 8:32 
GeneralRe: WPF TabControl Events [Edited] Pin
Pete O'Hanlon11-Jan-12 8:46
mvePete O'Hanlon11-Jan-12 8:46 
GeneralRe: WPF TabControl Events [Edited] Pin
Tom Delany11-Jan-12 9:28
Tom Delany11-Jan-12 9:28 
GeneralRe: WPF TabControl Events [Edited] Pin
Pete O'Hanlon11-Jan-12 9:56
mvePete O'Hanlon11-Jan-12 9:56 
GeneralRe: WPF TabControl Events [Edited] Pin
Tom Delany11-Jan-12 10:26
Tom Delany11-Jan-12 10:26 
GeneralRe: WPF TabControl Events [Edited] Pin
Pete O'Hanlon11-Jan-12 10:30
mvePete O'Hanlon11-Jan-12 10:30 
GeneralRe: WPF TabControl Events [Edited] Pin
Tom Delany11-Jan-12 10:37
Tom Delany11-Jan-12 10:37 
Questionnotificate that usb flash is connected Pin
mi_n9-Jan-12 19:26
mi_n9-Jan-12 19:26 
AnswerRe: notificate that usb flash is connected Pin
Abhinav S9-Jan-12 19:43
Abhinav S9-Jan-12 19:43 
QuestionHow to pass combobox value to chaild page in silverlight ? Pin
swap_ssj9-Jan-12 18:16
swap_ssj9-Jan-12 18:16 
AnswerRe: How to pass combobox value to chaild page in silverlight ? Pin
Abhinav S9-Jan-12 18:30
Abhinav S9-Jan-12 18:30 
QuestionOdd App Shutdown Problem (XP SP3) from .NET4.0 WPF/Prism app Pin
Jammer9-Jan-12 4:12
Jammer9-Jan-12 4:12 
AnswerRe: Odd App Shutdown Problem (XP SP3) from .NET4.0 WPF/Prism app Pin
Jammer9-Jan-12 7:36
Jammer9-Jan-12 7:36 

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.