Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Binding to a Command and Type Safety

$
0
0

Perhaps this is simply an uneducated question I am not sure. I use a number of Command Bindings similar to what is described here:
https://blog.xamarin.com/simplifying-events-with-commanding/

I like this approach quite a bit because it allows me to include virtually all code behind in the View Model. However, I am finding a few drawbacks that can sometimes cause problems.

1) When I bind a control in XAML the command (in this case "SquareRootCommand") does not refactor in Visual Studio with the attached view model. This causes problems when the command name gets renamed in the view model, leaving behind an orphaned control that no longer fires its intended command. Unfortunately, there are no compiler errors as I would have hoped. In fact it appears there not really any errors at run time either, Xamarin simply ignores the command.

2) Sometimes I forget to the declare the ICommand property in the view model as public. This again orphans the control because it can not reach the non public property. Again there are no compiler errors.
//Note the command is not public
ICommand SquareRootCommand { get; private set; }

Is this the intended behavior for Visual Studio or are there any plans to make the bound property/command in the XAML trigger a compiler error, similar to how an error is triggered if a XAML control EVENT is not properly found/wired up in the page code behind?

I understand the complexity that may exist since the design of the view model is not necessarily going to be defined the same way each time (it is not after all the code behind page file). However, is there an interface I should implement or a design practice that I should incorporate that may allow for more type safety in this regard?


Viewing all articles
Browse latest Browse all 204402

Trending Articles