Bernie Habermeier
Bernie Habermeier

Reputation: 2598

When to use mvvmcross data bindings?

I'm pretty new to mvvmcross, and have started to databind pretty much everything I display on the screen. Although it's usually not a lot of extra code, there is a bit of extra effort involved, and it certainly makes some things more cumbersome (say, when you have some conditional rules about screen layout that depend on the data itself).

There are quite a few cases in an app I'm implementing where data really is mostly static. Like, for example, when showing the times a restaurant is open at. That data simply won't change, and it's known at the time we initialize the screen. Because I'm somewhat new to the pattern I've been kind of just blindly binding stuff everywhere.

Now that I've done this quite a bit, I'm reflecting on how silly it is in certain situation to do the databinding at all, for what is essentially "read only" data that won't change.

I'm thinking I already know the answer here, but wanted to see what people think, overall. Are there reasons that are not obvious, where it's "better" to just data bind everything?

Upvotes: 2

Views: 278

Answers (1)

Kiliman
Kiliman

Reputation: 20312

Data binding everything is beneficial because it keeps your code consistent regardless of whether it is a one-way or two-way binding. There is no performance penalty for having a one-way binding.

You can also use data binding for hiding/showing, enabling/disabling, etc. elements in your layout. You can create ValueConverters to manipulate any property of your View.

The more logic you move out of your View and into your ViewModel, the more portable your code will be. Data binding is the bridge between your View and ViewModel.

Given all that, ultimately the only true answer is "It depends." Each app is different, and you'll need to determine what is the best way for your situation.

Hope this helps.

Upvotes: 2

Related Questions