Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Custom Controls in Xamarin

I've developed a few small apps with Xamarin as proof of concept, but I find it difficult to get solid information on some aspects of design. For instance, I need a specialty data entry control... It is not difficult, but I have question for things I have not been able to resolve.

The control in question is simple... it is a replacement for "checkbox"... In XAML I made a 1x1 Grid that overlays a Frame and a Label. I created Bindable Properties... a "Text" property (a single character in a the label (i.e. "A", "B", "C", "1" "2:, "3"), and "Selected"... a Boolean Attached Property that is used to determine "CodeCheckBox State... The control also contains a Tapped event, Command and Command Parameter bindables.

First Question, Should I be using a "Selected" property change delegate, or would it not be better to eliminate the code behind and use a XAML Data or Style Trigger... I have tried both... Code Behind works but the control is substantially slower in reaction to a tapped event than standard inline controls that I have used Triggers for... I would like to be able to have a Trigger on the elements inside the custom control XAML that would change the look and avoid any code behind all together, but I do not know how to reference the "Selected" bindable value. I have found conflicting references to how to do this, but none of these have world within the custom control. Most documentation associates triggers with inline "standard" controls and not within a custom. Thoughts on both approaches would be helpful...

Second Question, When the control is put on a Content View for use, it is necessary to get the Command and Command Parameter to work properly so that it will be possible to us an MVVM pattern to deal with the ModelView changes the control is designed for... Again, following numerous guides and documentation, I have not been able to get these to function... I do believe it comes down to Binding Context of the custom control, but there is limited resource or examples on how this works... Again, any guidance here would be helpful...

I have noticed the biggest difficulties with Xamarin development have to do with the Visual Studio IDE reporting errors on elements that no longer exist, I get anomalous "error in 'something.xaml' line -1. I can compile and run, but i'm used to cleaning up errors before I even try to compile. Then, developing a release with existent errors somehow seems foolish... This leads to difficulty with cascading thoughts on what is going wrong when things don't work... Is it the code for what I'm working on not work, or is the project itself somehow corrupt and what I'm currently developing not work... quite frustrating.

Thanks to everyone in advance... any help on any of this would be a great help.


  • StewartBasterashStewartBasterash USMember ✭✭


    I was able to complete a custom control with appropriate bindings including Command and Command Parameter... The problem remains...

    I created a custom control for the purpose of code reuse. I have to create a LIST of my custom controls so that someone can select them... this in turn has a visual representation that is all handled internally within the control. The Command and Command Parameter both work as long as the control is on a simple page with a simple viewmodel... In my case however, I am creating a list of controls, in this case it is within a FlexLayout. The moment I dynamically load these controls, I loose Command and Command Parameter functionality. I have noted in previous posts that i believe this to be a "binding context" issue... I have found a reference to broken binding references in ListView... I'm almost certain that this is the problem and I am still searching for a solution...

Sign In or Register to comment.