I'm building an application in Xamarin Forms targeting iOS, Android and ideally also UWP, but that's not absolutely required. I have a page which will have three ListView controls. Each ListView is databound with the items coming from the database. I'd like each of them to size so that all items can be seen without scrolling the ListView. Instead the page should scroll. I've tried changing the page so that the lists are contained in a StackLayout instead of a Grid, and have also tried various combinations of setting the layout and views' VeriticalOptions to ExpandAndFill, but each takes up roughly a third of the screen making the lists larger than they need (for the first two, which only contain a few items) or too small (for the third, which may contain a number of rows).
How can I get the views to resize and show all of their items?
Having a ListView inside a ScrollView is not recommended, i'd suggest to bind your three lists into a single ListView and then using TemplateSelectors and/or grouping to achieve the look and feel you are looking for.
You need to set a height on the ListView in order to achieve a fixed height. If the ItemSource for the list is dynamic I would suggest using a single list with grouping. Some details that might help you can be found on this related topic here.
If your list is static then just set the ListView.Height = <appropriate size> for each listview
Related
I'm am not good enough in WPF, so I'd like to ask for any advice how to implement panel layout something link displayed on image below:
So, the main purpose is to display a collection of items with possibility to select a single item, which should be moved to the first position (probably with animation) and then another item template should be applied to that container (it is bigger than other items in the collection). The list doesn't have to be infinitive, so just like a simple ListBox.
For me it looks like a FlipView but with a few items, which are neighboring siblings of the selected one and are also visible in the panel's viewport.
Please, advice me how to implement such a panel, or if you have seen something suitable, please, provide a link to the source.
You need to create your custom panel using User control.
Here is one example which is similar to your requirement.
In a Windows 10 UWP application I'd like to bind a collection of simple objects to a GridView or ListView and have the GridView or ListView autogenerate the columns based on the properties of the object rather than having to manually declare the columns and {Binding Path=SomePropertyName} on a TextBlock in the XAML.
This doesn't look possible.. is it?
Is there a different type of control other than GridView or ListView that will allow this behaviour?
Note: This is not WPF
TL;DR: This is not possible out of the box with the GridView or ListView controls.
In UWP a GridView is:
A control that displays data items in rows and columns.
The ListView is quite similar but only shows the items stacked in 1 dimension, by default vertical.
The DataGrid control (what this is typically called) is currently (as of SDK build 14393) not available in the default control set. With "some" effort you could write your own control for this behavior.
There are however multiple 3rd party solutions available, just google/bing for UWP DataGrid. Here are some of them:
MyToolkit.Extended NuGet package, more info on their GitHub page.
Libraries that might need a paid subscription/license:
SyncFusion
ComponentOne
Infragistics
You might find even more alternatives.
Can you write it in c# instead of xaml? Maybe it would be possible then, as long as you can access the container (gridview or whatever you use) beyond the constructor of your class. I'm not entirely sure if you can generate a new grid and switch on the fly but you could test it easily.
I've put together a scheduling application similar in style to that found in outlook, however it can show the schedules of multiple people. I have written a user control, basically a Border with gradient filled background & TextBlock. One of these controls are added to a Canvas at a set location for every appointment. The trouble is, I will have multiple users, with multiple appointments and may need to display 1000 or so appointments at a time. Initially, it takes an absolute age to instantiate all of these objects, however, I can live with this.
Unfortunately, the big problem arises when I try to scroll through the appointments. I have a couple of buttons to scroll left and right and upon clicking these, the UserControls' Left position are moved left or right a certain number of pixels - it can take several seconds between clicking a button and repainting(I also tried with labels just to test, but it was the same).
I guess the real question here is how to implement an interface, showing hundreds of controls with adequate performance and if this isn't achievable, how would I approach such an UI.
One possible option is a TextBlock CustomControl. You can get the exact same style as you have in your usercontrol but with a somewhat faster loading time.
Without a good, minimal, complete code example that reliably reproduces the problem, it will be difficult if not impossible to completely understand the performance problem you are having, never mind provide a solution.
That said, from your description it sounds like you are really looking to present the user with some type of ItemsControl, such as ListBox or ListView (a specialization of ListBox). In an ItemsControl, you can specify an ItemTemplate that defines how each item in the list will appear; this is analogous to the UserControl you apparently are using now.
I believe it's likely it will work fine just with that change alone. I.e. define your per-item visual as a DataTemplate instead of a UserControl, and set the ItemTemplate property of e.g. your ListBox to that template, then just bind your collection of appointment objects to the ListBox.ItemsSource property.
Note that the ListBox class already defaults to using VirtualizingStackPanel in its ItemsPanel template. So you should have no performance problems at all with this approach if you use ListBox.
If you want to use a different ItemsControl or create a custom one, you may or may not find that you need to use a virtualizing panel object explicitly (such as the VirtualizingStackPanel that ListBox uses). With just 1000 items in the list, even a non-virtualized panel may be fine, but if not then even when not using ListBox, you can always specify it explicitly.
I'm trying to accomplish what should be a very simple task using the ListView Control. All I am trying to do is add two Items to a ListView Control. One Item goes under the "Title" Column and the other Item goes under the "Status" Column. I have seen many examples for the ListView Control and none of them cover this particular need.
I've read the MSDN documentation on the ListView Control and find it rather odd they don't mention this... Or maybe I've overlooked it?
In ListView parlance, these are not separate items. It sounds like you want to add one item, and then what ListView calls a subitem. Assuming that Title is your first column and Status your second, you want:
ListViewItem myItem = listView.Items.Add("My Item's Title");
myItem.SubItems.Add("My Item's Status");
If you are just getting started with a ListView, you can save yourself a lot of time, headaches and frustration by using ObjectListView -- an open source wrapper around .NET WinForms ListView.
It solves many problems that you are going to find while trying to use a ListView, as well as just making it much easier to use. Just one example: it automatically handles sorting rows by clicking on column headers.
I would like to store and display a list of complex items. Each (graphic) item has to display an image, a list of color chips, a label and an index (a letter). User would also be able to zoom within each item, to show details of the image (on mousewheel),
Items would be presented in a vertical list, scrollable and resizable.
Language is C#, .net2.0, or 3.5 only if necessary.
I'm think about using custom UserControls for items (each one composed of a PictureBox, 2 Labels and a custom UserControl to display color chips).
For the list, I really don't know what to choose between a ListBox, a ListView, or a DataGridView, or another one I don't know yet.
I basically would go for a ListBox for its simplicity. Could you help me clarifying the advantages of using other lists?
If you expect to have a large number of these items, I strongly recommend that you do NOT make each one a UserControl. This is doubly important if you intend to localize and globalize the application at some point. The creation of these items will hinder performance.
Instead, take a lighter weight approach so that the items don't have the overhead of a full-blown control. Assuming that each item will be rectangular, you could easily create a UserControl for painting them, including a scrollbar to scroll.
in your case a custom (third party) list control seems to be the way to go. ListBox, a ListView or DataGridView are rather too limited given your requirements.
Regards,
tamberg
Thanks for your answers. It's very helpful to me.
I'm sorry I didn't mention that the list and its items have to manage drag-dropping with other controls. Then, I suppose that items have to be separate controls. Also, list would be dynamic and would not contain more than 30 items.
So, if I understand your advices, I should create a custom UserControl for the list and one for the item.