简体   繁体   中英

C# Binding variables between classes

Is it possible to bind a variable from one class to another variable in another class?

I am implementing MVVM in a windows phone 8.1 app and I am new to windows phone. What I am trying to do is: I have one Model with a DateTime Property and I want to get the value of that property transfer it to the code behind of my mainpage.xaml.cs calculate the elapsed time and display the elapsed time to the UI.

I have tried somethings but without any luck.

"transfer it to the code behind of my mainpage.xaml.cs" is not MVVM. In MVVM, your ViewModel has properties and you bind them in your View.

Here, you could create a ViewModel with a property TimeSpan ElapsedTime (with the usual change notification), and automatically update (recalculate) it every second using a timer such as DispatcherTimer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM