I've created a UICollectionView and was wondering if there was a better way to create tight wrapping for individual cells in the view. Right now, if there is a larger cell in a column, the rest of the cells in that column become centered, like so:
Is it possible to achieve something like this?:
This is possible, but it won't be using the default layout. You'll need to write a custom layout subclass.
Related
Right now I use 2 arrays one of TImage the other of TMemo to draw an image next to text data row after row inside a scroll box.
I am looking to replace the TMemo with several components on a Panel. So probably some static text a button and some labels. But the way I'm doing it now it seems as if this will become messy.
Is there a better way of going about this without writing a component or class. Should I be using some sort of multi dimensional array or can I use a record structure to declare the components and have an array of that?
A record would at least relieve you of the burden of managing lots of parallel arrays, but you can do better than a record, and better than an array.
First, you can design a frame to represent one "row" of your form. Give it an image, button, label, and whatever else you need. Then create an instance of that frame class each time you need one. It will create the components for you automatically. You said you didn't want a custom component, and that's essentially what a frame is, but by getting to design it visually like you would a form, much of the burden of creating a composite control is lifted, so you just get the benefit of a group of related controls that can interact with each other as a unit.
Instead of an array, you might find better success with a different collection object, especially TComponentList which can grow and shrink more easily than an array, and also helps manage ownership of its contents.
I am looking to display tabular data (tv channels), but with options such as DataGrid/UniformGrid/Table with FlowDocument/etc. I cannot figure out what would be the best option. The main issues is that the cells aren't uniform in size as it varies based on length of time, and I would like to put padding between them as well. Additionally, I need to only be able to display a portion of the table, and allow them to scroll Up/Down/Right to view the rest.
What would be the best WPF Control Option for this? Here is a small illustration of what I am going for. The white square in the upper left is what I would want to display at start, and allow them to scroll to the rest of it.
There are several ways to accomplish what you're trying to do here. If performance is not an issue then I would ignore virtualization and try the DockPanel The drawback here is that you would have to add the items in order rather than adding them by row.
Another option would be to use two stack panels (one in each direction). This addresses the adding issue, but requires the use of more panels.
Both of the previous two options would require individual items to have their height/width set.
A final option (depending on how large your grid is), would be to use a Grid with fixed sized rows and columns with items that span rows (using the rowspan property). The drawback of this method is that I don't know of any good way to create this control in xaml for unspecified numbers of rows/columns so you would have to create it in code to get the needed number of rows/columns.
If you have performance issues you could try using the VirtualizingStackPanel. If this still doesn't meet your performance requirements then you will need to subclass the VirtualizingPanel and tailor it to meet your specific needs.
See here for more information on Panel performance.
I suggest trying the two StackPanel method first, then the VirtualizingStackPanel method and finally, if that doesn't work, then try the VirtualizingPanel
Padding is easily accomplished by setting the Margin property on each subcontrol.
For scrolling use the ScrollViewer
Basically I use lists to display information, these lists contain custom data items I have created, they all look similar and have some of the same controls in them, essentially they need to look the same colour, font etc. At the moment, I just seem to be repeating code over and over each time a change is needed i.e. colour.
I have been wondering if it would be a good idea to create a generic data item which all the lists use and then just collapse controls which aren't needed.
So I was going to create a user control called something like "GenericDataItem". This data item will contain all the controls that each data item would need, then use dependency properties to collapse controls not required.
My question is would this be the right way to go about this, or is there a better way?
Thanks.
Not sure I got the point, but using DataTemplateSelector could help you.
I need to write an excel-like grid that can have a lot of cells (400x400). All columns have the same width and all rows the same height. Each cell can contain text or be empty and each cell can have a column and/or row span. I suppose this will never work with the Grid panel and I suppose I will need UI virtualization in both column and row direction.
So my first try was to create a virtualizing grid by deriving from VirtualizingPanel and implement IScrollInfo. This could have "easily" be the solution except that I ran into a problem:
To provide IScrollInfo with the relevant information about scroll size and position and to be able to detemine wich items need to be created (realized) next using the ItemsContainerGenerator, I need to know the column index, row indeox and columnspan for each child item (cell). The only way I can think of to do this is using attach properties. The problem is: I can only read the values of attached properties if the ItemContainer that has them is already realized. So I am in a catch 22 here. To know what to realize I need to realize all items. To provide the data for IScrollInfo I need to realize all items.
So it seems that I am at a dead end with this approach.
Do you have any idea how I could implement a control like this or know how I could reslove the above problem?
It strikes me that you may not need to instanciate the UI elements themselves- you can very easily have a collection of DependencyObject-derived viewmodels, each of which has the WidthProperty and HeightProperty set (and possibly bound to the equivalent Width and Height properties of the visible cell UI element, once those are created).
Storing 160,000 (400x400) class instances shouldn't be a problem, especially if you are able to index into the set using row and column.
When building WPF forms that are used for data entry (e.g. A bunch of labels next to a bunch of textboxes and comboboxes) I've seen two methods:
Create a master Grid, divide it into two columns, and add rows with Height="auto" for each field and two rows for header and footer (and submit button), and each label and text box has their own row.
The other method is to create a master stackpanel and inside it a horizontal stackpanel for each pair of label-textbox.
How do you design your data entry forms? I'm currently torn between the two methods, maybe there's an alternative that I'm unaware of?
EDIT: Henk said I should define best and I think I agree, by best I mean easiest to maintain, create, align and add or remove fields from as demands change.
So far the only criteria by which the grid is better is ease of alignment.
definately first method!
it's well aligned, especially with the use of SharedSizeGroup so you can have the same alignment eg in different Groupboxes.
I have used both and it really depends upon how your form is going to look. If you have a really simple layout where you are going to have labels and and corresponding fields of approximately the same size then your first method works well. It lets you create two columns that line up very well. However, if your fields are of varying withs, and heights and you want to be more complex with the layouts then a hybrid approach may be best. If you are doing anything more complex than just labeling fields on basic controls you may want to create user controls rather than just using what is there out of the box. When laying out fields in both a horizontal and vertical jagged manner it becomes hard to maintain the grid layout as you have to wind up having a grid with lots of columns and rows. The fields and labels have to span columns and rows to get your alignment correct. This works, but is a nightmare if you ever want to reorganize the form.
For what you wrote, it sounds like the first approach is best. If its simple now and some point in the future it becomes more complex, its easy to change. However, if you have a more complex layout already then a pure grid based approach probably isn't best.
Disclaimer: I am going to say little about my own company's product in my blog that gives comparison and challenges in maintaining forms.
Both Grid and StackPanel have Maintanence nightmares so we went on different approach of creating Form Layout, and I have outlined our approach here on this link,
http://akashkava.com/blog/296/advanced-data-form-with-ui-atoms-on-wpf-and-silverlight/