Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Passing and consuming Command's to a ViewCellRenderer with centralised business logic

$
0
0

Hi All,

I am new to Xamarin and have recently started my first project which is a conversion of an app originally written for Android. I was faced with the prospect of converting to IOS and then WinPhone and figured Xamarin would be a much better option in the long run. Only time will tell :)

Anyway, I have come across an interesting problem that I would like to share with the community in the hope that someone else has faced this same issue in the past or at least has an opinion on a solution.

**Problem:

My app requires the need for a messaging interface; identical to nearly every other text based messaging interface except for the fact that one of my message types is a question that requires a question and "Yes" and "No" buttons to be embedded into the message itself. When the user clicks on one of the buttons some business logic is executed updating data and sending reply messages etc.

**My Solution: (So far...)

I have created a custom ViewCell and associated ViewCellRenderers for each platform.

As I would like to have the business logic centralised back to the ViewModel, I am trying to pass some Command properties to the ViewCellRenderers that can then call back to a central function.

The custom ViewCell has two properties called "YesCommand" and "NoCommand" of type "Command". These properties are bound to functions within the ViewModel for the ListView that contains the custom ViewCells.

Believe it or not everything seems to work with the exception of the "Command" properties always seem to be null.

Have I over complicated the solution?

Is their another way to achieve this?

I have attached the code if anyone is interested.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>