c# - Alternating Row Colors in Xamarin Forms ListView IOS -


I am trying to write a custom renderer which can allow a list view to rotate in row colors I have gone into an issue and I am not sure whether this may be a bug or I am not implementing the renderer properly:

My expectations for the following code are that each custom view The cell should be color based, however, on this condition, it Is restricted to those that do it, I believe the code tv.IndexPathForCell (cell). Row should return the index of the cell but it is not working as expected, it is currently returning a blank value (if it is not in the cell part), but I believe that cell The table is part of the view and thus my problem is if I exclude var index = tv.IndexPathForCell (cell). and then set the background color constant value and see that it works correctly. Apart from this, an exception is thrown due to zero value and the cell is set on the base and shows the scene with a default background.

Am I doing something wrong, I have tried many other things but I believe it should be the right way to do this.

C # code: [assembly: export renderer (typef (custom vivekel), typef (custom vscellorender)] namespace AIM. IOS {Class Custom View Cell Renderer: View Cell Renderer {public override UITableViewCell GetCell (cell item, UITableView TV) {UITableViewCell cell; Try {Cell = base.GetCell (item, TV); Var customcell = (customvusel) item; Var cell = base Gatesel (item, TV); Var index = tv.IndexPathForCell (cell) .ro; Cell. Background Corre = (Index% 2 == 0)? Color.gray TOUIColor (): Color. White. Uololor (); } Catch (Exception pre) {string message = ex.Message; Cell = base.GetCell (object, TV); } Return cell}}}

I am expanding the expanded viewless class from Xamarin-Forms-Labs which adds background properties to the ViewCell object. Public class custom visuals: expanded viewsel {public customvusel () {}}}

here is XAML:

  Namespace AIMUI.Controls {Public Class} Pre Class = "Lang-XML Happy Print-Override">  & lt; Local Control: List View & gt; & Lt; ListView.ItemTemplate & gt; & Lt; DataTemplate & gt; & Lt; Localcontrols: CustomViewCell & gt; & Lt; Localcontrols: CustomViewCell.View & gt; & Lt; / Localcontrols: CustomViewCell.View & gt; & Lt; / Localcontrols: CustomViewCell & gt; & Lt; / DataTemplate & gt; & Lt; /ListView.ItemTemplate> & Lt; / Localcontrols: ListView & gt;   

Edit:

OK, so I get the issue of indexing using the var index = tv.IndexPathForRowAtPoint Resolved cell. Center) .ro; , although it has caused another problem, it works entirely for the first time, as well as coming back to the page from the sub-view. However, when I leave the page and come back to any other view from masterpage then it sets the background of all colors to gray. Currently, I am creating a new page and then I'm setting it on masterpage.details when coming from the menu.

This can be done using a converter rather than a renderer.

  Public Class Stripe Backfusion Index Control: iValueConver {Public Object Convert (Object Value, Type Type Type, Object Parameter, Culture Info Culture) • Return (if value == empty parameter == blank) . Var Index = ((ListView) parameter) .amsource.cast & lt; Object & gt; (). ToList () IndexOf (value); Return Index% 2 == 0? Colour. White color. RMRBB (240, 240, 240); } Public Object Convertback (Type Object Value, Type Type, Object Parameter, Culture Information Culture) {New Non Imulated Expansion (); }}   

Then name your ListView and give it as parameter using X: Reference

    

Of course you can use the converter in your renderer if you need to customize the other elements.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -