WPF immutable property binding

I am using the MVVM pattern and I have POCO (in my model) with the property "Start Date".

I want to show elapsed time from the start date in a control in a window window / WPF user element ...

I don’t see how I can bind the ModelView property to the user interface control and update it automatically ... can anyone suggest a way?

I could use something (a timer or a thread) to update the duration property in my ModelView, but I just don't see another way, because as far as I understand, the user interface will only be updated when the property value changes. However, the start date of my POCO does not change it only for the elapsed time, which changes the value, which is the calculated value.

Did I miss something?

+3
source share
1 answer

You are on the right track. Look at the Presentation Model template on Martin Fowler's page.

The basic idea is to create a model for the user interface (ViewModel), and the user interface simply synchronizes with it. Each bit of information displayed in the user interface must have a corresponding field or property in the ViewModel (although they can be obtained or obtained from values ​​in the model). ViewModel makes it easy to save the view state / session state (for example, the current selection of items in the UserList) that is missing in the Model class behind.

" " , ViewModel ElapsedTimeSince. WPF , . , , , /, , Model StartDate. .

+3

Source: https://habr.com/ru/post/1703117/


All Articles