Xamarin Forms - Get custom control runtime (with valueconverter?) - xamarin.forms

I have a Xamarin forms application. It has a page. That page has a listview. The listviews is bind to a sourcelist. What I want is to decide what custom control to use based on a specific property that each item in the list has. How can I achieve this?
It is also required that the custom control binds to values from the list.
I tried the following:
<ContentView Content="{Binding IsPriority, Converter={StaticResource RoadIndicatorBackgroundValueConverter}}" ControlText="{Binding TowingOrder.Location.RoadIndicator}"></ContentView>
That won't work because I can't bind with the ControlText of the specific custom control.
The image above shows the problem. The A1, A50 and the blue icons are all custom controls, those aren't images. There are some more of these custom controls. I can't just make 10 datatemplates right and copy paste everything? That would be so much duplicate code. Can't I just use a base object in a datatemplate, and bind a property with a converter and use a switch/case to decide which custom control to return?

It is not a good design to binding the content of whole layout in runtime.
From the screen shot , it seems that each cell are similar .So you could create a base Custom Control and define all controls in advance and binding the propertyIsVisible in code behind . Then set its value to control which element should been displayed .
If there are do many dig differences between the cells , use DataTemplateSelector is better .

Related

Devexpress DataLayoutControl - how to add controls

Is there any way to add or remove controls to/from a DataLayoutControl in DevExpress without deleting all the existing controls? If so, how? I'm using Visual Studio 2017.
DataLayoutControl manages layout items containing child controls. If you need to create a new item, create a new LayoutControlItem as shown in this class description.
To remove a layout item, use the LayoutControl.Remove method.
The Items help article should be also useful since it illustrates how to operate layout items and controls.

Datasource in create and "normal mode for the same form

I would like to create a single form that I can bind to a datasource in create mode and in "normal mode". The use case is that I can have an existing item in the datasource that I would like to edit, or I would like to create a new one.
I can't find a way to dynamically switch the datasource mode before opening the form. It seems that 2 forms are required to accomplish this.
Any suggestions on how to accomplish this?
It is possible to reuse form fields, but you'll still need at least two forms (containers). The idea is to create a page fragment with datasource derived from some model:
then you can add this page fragment to form (container) and override datasource.
Normally you would choose between normal mode:
#datasource.item
...and create mode:
#datasource.modes.create.item
You can find complete code sample in Project Tracker template and learn more about create mode in docs:
https://developers.google.com/appmaker/models/datasources#create_mode_datasource

Xamarin Forms Button set Content

I have a very common problem, but I couldn't find any valid solution.
I want to create a Button able to contain more than a simple Label or Image. In fact, Xamarin Button exposes only Text and Image properties, but in my case I want to construct a more flexible set of controls (e.g. a StackPanel with a list of controls).
I implemented a ContentView acting as a Button after having added TapGestureRecognizer and it works from the pure functional point of view. What I don't like is the missing of all Visual States of a Button.
Therefore, I was thinking how to implement a Custom Renderer of a Button. I would like to expose a ContentPresenter BindableProperty and then set that property to the Button.Content (speaking in UWP terms) in the Renderer class. I think this could be a solution, the problem is that I don't know how to "cast" a Xamarin.ContentPresenter to a UWP.ContentPresenter. Do you have any idea about how to implement a Button able to contain any generic Content?

How to increase list View's Separator length in Xamarin forms iOS?

I want to increase list View's Separator length(spacing between two cells).
I am not getting how can I do it in xamarin forms by using custom renderer and I am looking for iOS only.
I want to create card view in iOS (by using xamarin forms) just like facebook application.
I Implemented it with frame control.
1.I created one customized cell in List View (Using ViewCell).
Then Added frame in it.
2.Removed Separator in a List View by Using Custom Renderer.
Use HasUnevenRows="True" in your ListView and it should adapt to your item height.

How do I handle application views in Flex?

I have a Flex application with three different views. Only one view is shown at a time, and the choice of view depends on what part of the application the user is working with. If it had been an ordinary HTML webapp I would have created three different HTML-templates/pages for each view.
What is the recommended way to handle such application views in Flex?
The behavior you want is usually accomplished by using a ViewStack component. In MXML you declare child containers for each view you want, but only one gets shown at a time. You can change which one is shown programmatically whenever conditions are met by setting selectedIndex on your ViewStack. By default the first child container is displayed when run. Another approach is to declare and use states in your container and change currentState whenever you need to change the view. Hope that helps.

Resources