Xamarin Forms : Adjust listview rowheight based on a condition - xamarin.forms

Is it possible to adjust the row height of a listview based on a condition?
My Condition: If the value of {Binding isMediaUrlNull} is true set the height as 250 else 500.
Either in xaml or in class I need to add this condition. For avoiding the blank space between the items I am applying this.
Please suggest a solution for this :)
Thanks in advance

It may be possible to set the HeightRequest of the Grid that is the parent control in the data template to one of your 2 heights based on a binding condition.
EDIT
Just spun up a quick app to check and yes you can bind the HeightRequest of the parent grid to a Model property.
Make sure you set the HasUnevenRows property of the ListView to True.

Related

How to access child views of CollectionView?

There's a few cases where I would like to access the child views of CollectionView. Here's a few examples of why:
CollectionView doesn't set the Selected VisualState on the selected item, when the item is not a reference type (for example an enum), and the SelectedItem is set in code, either by setting the property, or by data binding. So in order to support the use enums in my CollectionView, I want manually set the VisualState when the selection changes.
CollectionView always has the height of 100% of screen height. It's not very practical in many situations, and in some cases where I know it's only a few items, I want to calculate the height of all children, and set the HeightRequest of my CollectionView accordingly.
As a workaround, I've used StackLayout with BindableLayout.ItemsSource instead of CollectionView. Here, I had access to the child views, and am able to set the VisualState of children as I please.

An item renderer with autosize

For example, I've created 2 horizontal lists with different heights: 50px and 100px.
I'd like to use 1 item renderer to display both.
The item renderer has to create square items, so it has to produce 50x50 items for the first list and 100x100 items for the second one.
How should I set up the item renderer to get the result?
It is always the parents responsibility to size it's children. In this case, the list is the parent and the itemRenderer is the child. The best you can do is offer suggestions in the way of measuredWidth and measuredHeight.
So, you could override the measure method of your itemRenderer component to set the values (50x50 or 100x100) based on some criteria. But, what would that criteria be?? We don't know because it wasn't provided inyour question. In an ideal world, it cannot be the height or width of the List; because the itemRenderer should know nothing about the list.
Ignoring the itemRenderer for a moment...
In an MX List, you can use the rowHeight property.
In a Spark List, you can set the rowHeight property on the List's layout.
You may be able to use a typicalItem on the List class instance.
I think these approaches are more likely to give you the results you want than doing something in the itemRenderer.

Flex - How To Modify The Verticle Gap In A Repeater

I Have a VBox, and set the verticleGap = 0. Inside the VBox I have a Repeater. When I run the App, the items listed from the Repeater have a large gap between each line. Is there a way to set the verticleGap on the Repeater, or reduce that space?
Thanks
Two things: First, the property is misspelled, it should be "verticalGap" for your VBox. Second, if your repeated components are all the same height, you could set an explicit height for your Repeater component, such as height="22". Hope that helps.

Adapting the width of a Flexs 3 DataGridColumn to the content of its ItemRenderer?

I have the following scenario :
A Flex 3 DataGrid is sitting here
At runtime, a column is added to this grid
The column has a custom ItemRenderer
The ItemRenderer inherits from HBox, and adds a few items to the HBOx dynamically
My problem is that the width of the column doesn't change. As a consequence, my column stays small, and an ugly horizontal scrollbar is displayed in the line, instead of my content (which is completely unreadable).
I would like the column to adapt its width to the content of the HBox in the ItemRenderer. I tried the following :
Setting the 'percentWidth' of the ItemRenderer to '100'
Invalidating the properties of the ItemRenderer after adding the items
The only thing that has a "visible" effect it to force the width of the DataGridColumn. Obviously this is not acceptable since I'm dynamically adding components to the ItemRenderer, and I don't know how many or how big they are.
Besides, when I am in the ItemRenderer, I have no access to the column itself (or do I ?) so I cannot force the size of the column from here.
So is there a way around this ? Would AdvancedDataGrid help here (notwhistanding the fact that I cannot really use it for other reasons ...)
Alternatively, I would be happy enough if someone has a solution where the column cell is displayed without the ugly horizontal scrollbar (don't mention setting horizontalScrollPolicy to "off", been there, tried that, lost shirt ;) ).
Thanks
PH
I did not found a solution for the size, however I found the way to remove the scrollbar ; you must put the "horizontalScrollPolicy : 'off'" in the list of properties of the itemRenderer Factory (rather then on the itemRenderer itself).

QTreeWidget set height of each row depending on content

I want to make editable cells with multi-lines content in QTreeWidget and I use for this purpose QPlainTextEdit as a delegate. I need to set proper size to all rows that switching between editing and displaying went smooth, without any visible changes.
rect = textEdit.blockBoundingRect(textEdit.firstVisibleBlock())
With this I can find out the height I need to set for the row, but I missing the place where I can do it.
How can I set proper height to QTreeWidget's rows on initialization stage and how to handle it's changes?
You need to reimplement delegate's sizeHint(). It will automatically handle row's height and width.
And note, that QTreeWidget::uniformRowHeight property must be false in this case, though it will slow tree element rendering if it contains many rows.

Resources