Complicated customized ViewCell with grids issues

christopherpolskachristopherpolska ✭✭✭PLUniversity ✭✭✭

Hi,

I want to create a ListView that will contain very customized cells - customized means that they have: at least 6 labels, 1 image, 1 button and another "thing" described below. My current solution is this:
1. I've created custom viewCell class
2. Added a Grid to contain all UI's elements (grid is 2 rows by 12 columns)
3. The first row contains all UI's elements
4. The second rows spans on all 12 columns and contains my own TimeLineSlider- the "thing" ;) (its just to show particular information to the user). The second row is around 40 in size
5. I have created a class (lets call it PersonClass) to hold information that goes to the UI's elements (so I have string FirstName, string LastName)
6. I have created a DataTemplate to bind those elements with elements from the PersonClass class.
7. The TimeLineSlider is written in AbsoluteLayout and I am getting it by calling MySlider.GetSlider().

And now the issues:
I can wrap my AbsoluteLayout of TimeLineSlider into ContentView or a Grid and return it. Also, for each person I want to have different slider, so in the class PersonClass I also have a field type of ContentView or a Grid - I tried both.
When using ContentView:
1. The slider is displayed on the screen, if the list contains 2 elements, then I will see 2 sliders - as expected. However they are under the list... so I have 2 normal cells with information from other PersonClass fields, but those 2 sliders are going to be under the list. When clicking on an item, I can see that slider is also blinking (like when u click) and then it disappears...
2. this is the code for binding:

var slider = new ContentView(); slider.SetBinding(ContentView.ContentProperty, "Slider");

When using Grid:
1. The slider does not show at all :neutral: but I can see in debugger that the list is filled with those sliders so they are being generated.
2. When using the grid, you can see how the structure looks: ListView->Cell->Grid->Rows/Columns->Grid->AbsoluteLayout....
3. this is the code for binging:

var slider = new Grid(); slider.SetBinding(Grid.BindingContextProperty, "Slider");

Can I please receive some help with this? Both: fix those issues, choose the correct Grid/ContentView and of course suggest another way of doing the whole thing.
Thanks :)

Answers

  • JulienRosenJulienRosen ✭✭✭✭ CAMember ✭✭✭✭

    since you are manually injecting content into your viewcells, you have to tell them to re-evaluate their size. you can do this by calling ForceUpdateSize on the cell after you have changed its content.

    i would recommend using DataTrigger or DataTemplateSelector to accomplish your goals though, and not try to inject via c#

  • christopherpolskachristopherpolska ✭✭✭ PLUniversity ✭✭✭

    From the code I can see that inside my DataTemplate, the labels are filled with data, and the slider isn't :/ I think that it might be the wrong binding:

    var numberLabel = new Label { HorizontalTextAlignment = TextAlignment.Start }; var timelineGrid = new Grid(); numberLabel.SetBinding(Label.TextProperty, "Number"); timelineGrid.SetBinding(Grid.BindingContextProperty, "TimeLine");

    Does some one know if this is the correct way?

  • christopherpolskachristopherpolska ✭✭✭ PLUniversity ✭✭✭

    @JulienRosen said:
    since you are manually injecting content into your viewcells, you have to tell them to re-evaluate their size. you can do this by calling ForceUpdateSize on the cell after you have changed its content.

    i would recommend using DataTrigger or DataTemplateSelector to accomplish your goals though, and not try to inject via c#

    I think that those DataTemplateSelectors are good when you want to dynamically change appearance because of some reason. I don't need that, every cell will look the same (the content of labels will be different and also of the AbsoluteLayout mentioned earlier). But anyway I am using the DataTemple which is similar.

Sign In or Register to comment.