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.
Related
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.
I need to access currently visible rows (first, last) from a JavaScript function, that is defined inside a TableView.
TableView
{
function getVisibleRows()
{
...
}
}
I see that ListView (what is a Flickable) has a contentY property which would make the problem trivial, but TableView has not. Also, TableView is implemented in terms of a ListView, so there is a ListView involved, but I am not sure how to access it.
Thank You!
I've figured out. I simply need to access flickableItem.contentY.
Use the viewport property of Scrollview (inherited by TableView), which
determines the current "window" on the contentItem. In other words, it
clips it and the size of the viewport tells you how much of the
content area is visible.
viewport return a complete qml item so you can get a lot of position data.
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.
I've got a combo box like this:
<mx:ComboBox dataProvider="{someArrayCollection}" />
But when the contents of someArrayCollection change, it leaves the combo box too small:
How can I trick the combo box into automatically resizing to fit the label of the largest item?
So the problem is that the ComboBox doesn't invalidateSize() after the dataProvider dispatches a COLLECTION_CHANGE event.
Lame.
It can be fixed by calling myComboBox.invalidateSize() when ever the dataProvider dispatches a COLLECTION_CHANGE.
Basically, you just loop over the dataProvider, measure the width of each item's label, and keep track of the largest one.
I sort of built this into the Flextras AutoCompletComboBox. There is a property named expandDropDownToContent which expands the drop down so it has no scroll bars, but it will not inherently expand the prompt portion.
The Spark DropDownList has a property named typicalItem which does something similar. Oddly that property does not seemed to be defined in the DropDownList at this time.
12/23/3011 update
Since this keeps getting downvoted, I wanted to explicitly state. When the MX/Halo ComboBox sizes itself automatically, it does so based on only the initial items that will be displayed in the drop down. If you don't loop over all items in the dataProvider to determine the proper size of the ComboBox/DropDown then items may be cut off regardless of whether you call invalidateSize() or not when items in the dataProvider change.
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.