Making UI Elements globally available

87 views
Skip to first unread message

Sven Trash

unread,
Mar 1, 2016, 5:10:01 PM3/1/16
to MvvmFX
Hey there :)

I am currently trying out your framework and have a small problem. My user interface is devided into three parts, each has its own ViewModel and View as well as a own fxml file:

1) the menu bar.
2) the main content area (a textarea)
3) the status bar (a HBox containing a Label for messages and a progressbar for updates)

I know want to make the ProgressBar and the Label globally available (atleast the ProgressProperty and TextProperty) so I can inject them into some ViewModel and use them for updating  the user. Is this managable? If yes, how do you exactly achieve this? I looked into the Scopes which seemed like what I am trying to do but I couldn't create something working that felt right (By fealing right I maily mean elegent. The only working code I wrote was the StatusViewModel holding a String and DoubleProperty. The StatusView binds those properties to the progressbar and label. After that, the ViewModel binds the fields again to a scope. This somewhat felt not really elegent and I probably made something wrong). It would be really nice if someone coould help me out :)
I also added my eclipse project. If you run the VoiceApplication, you will see the user interface and at the bottom the progress bar and label (for those that may need the soruce code).

Have a nice evening,

Sven
project.zip

Manuel Mauky

unread,
Mar 17, 2016, 1:06:46 PM3/17/16
to MvvmFX
Hi Sven,
sorry for the delay. I've looked into your code and according to your description I think too that scopes are the best way to go.

The StatusScope can be injected in all classes that need to update the scope without the need to know how this status updates are visualized. The scope only represents the data and this way components are decoupled from each other. No implementation details are shared.

Let me know if you are still in doubt about using the scopes for your use case.

best regards,
Manuel

Sven Trash

unread,
Jun 21, 2016, 9:37:53 AM6/21/16
to MvvmFX
The problem that I faced was that I have a normal property in the scope that holds the current value of the progress from 0 to 1. The ViewModel triggers an update action (a command). Its progress value gets bound to the scope values so they update automatically. The problem is that I now cannot bind the properties in the scope to the actual view. They do not let me have a 1 to N relationship. Any idea on how to fix this?
Thanks,
Sven
Reply all
Reply to author
Forward
0 new messages