15,918,193 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by bnmc (Top 3 by date)
bnmc
28-Jul-16 10:42am
View
Thanks for the reply J. Calhoun; must have missed it.
I think I figured out a good direction to head in, due to replies to my other posted question. The base question here is, should I include the calculation properties in the Model objects, or a wrapper for those Model objects, such as a ViewModel.
I've decided to only bind directly to the ViewModels, so I only create the calculation properties in the ViewModels. But since the ViewModel is acting as a wrapper, and that I want to include totals in the DataGrid in the View, I need to have ObservableCollections of things like TicketsViewModel.ObservableCollection<ticketviewmodel>. Then when a user selects one of those items, the SelectedItem changes which is bound to TicketsViewModel.SelectedTicketViewModel. In TicketsView, there is a UserControl which has it's DataContext set to SelectedTicketViewModel; so it updates every time the user clicks on a different item. Seemed the easiest/best way to do it.
I will look at Observer Pattern again as I think it could make other things a little easier.
bnmc
5-Jul-16 12:55pm
View
Thanks for the reply Super Lloyd. It's amazing that this concept isn't discussed much and only seems glossed over. And, the argument from many developers on where to locate some things as it relates to MVVM, makes it more difficult to work this out. Thanks for confirming this is accepted.
I did finally find an article though I hadn't stumbled on before. It discusses just this, about what the responder found confusing. Specifically, "Another kind of object that fits in the ViewModel layer is a wrapper around a Model object that gives it behavior and makes it more usable by a View..." The author goes on to mention about "thick" vs. "thin" ViewModel layers. I strongly suggest reading his response, as it also has a very good explanation.
http://stackoverflow.com/a/5422692/4429864
With your answer and the article I found, I'm going to mark your response as the answer. Thanks for confirming this is an acceptable way to do it!
bnmc
23-May-16 13:41pm
View
Thanks for the response Kassim. Your answer provided good insight, and ultimately pushed me in the right direction for the final answer. I don't plan to use any code-behind, so thanks for the reference to "use appropriate command from the view model," otherwise that would have been confusing.
I was still confused though, as what you reference was like what I provided as the XAML I tried already; just not able to figure out how to reference things correctly. I found though that I needed to use "DataContext" in a couple more places to get things to reference correctly. What you show for the header and using DataContext.Column to reference the value directly, gave me the "a-ha" moment. With a little searching, I was able to use elements of what you suggested, examples online, and a little tweaking; to find the final answer. I'll post it as a separate solution, so I can mark up the XAML for easier viewing.