I am looking for a layout control or other means of laying out data in a tabular format on a Fixed Document for reporting. I have used MigraDoc quite extensively in non WPF projects and its table object allows for a granular layout for each piece of data to be displayed in the table. Borders can be turned off on the cell level, columns can be merged/spanned, etc. Are there any controls that offer this kind on control within WPF? I have not seen where the DataGrid or the Grid will do what I need... easily. My data is not bound as I need to have full control over how it is displayed. I am not using a flow document so I cannot use the table object that it offers. Anyone have any suggestions? For now, I have resorted to programmatically creating a Grid and then inserting a Border containing a TextBlock within each cell. There just has to be a cleaner way!
BTW - I am looking to use native WPF controls in this project which is the reason that I am not using MigraDoc.
Related
I am new to WPF. I want to design a Datagrid similar to mail list in outlook 2013 having same style and features.
In outlook 2013, Datagrid template changes when its width decreases and goes to one liner type of mode when it expands.
I tried to implement this behavior with two separate Datagrid controls (only one control will be visible at a time), however, I faced lot of issues. Changes occurred in one grid have to reflect on other grid. I think its an indirect method. Can I achieve this by using single control.
I am not sure if you are familiar with Triggers, however I would suggest you to apply a Trigger to your Style based on the control's width property and change it's style the way you wish to be.
Here is a very good tutorial about Templates and Triggers from Josh Smith that you can learn from. In fact, have a look at all the parts of this tutorial if you want to learn more about WPF best practices.
A Guided Tour of WPF – Part 4 (Data templates and triggers)
Meanwhile since you're looking for a Trigger value to be a range rather than a certain value, say (Pseudo) Trigger when ListView's width < 300, you will need to use a custom converter with your trigger.
For an example of such converter look into this question
WPF Trigger when property value is greater than a certain amount
I am trying to display items in a grid however the rows and the columns should be generated dynamically. I actually implemented a custom control that derives from Grid control and provide additional properties such as RowCount.
Here is a picture of the grid generated by my custom control using two dimensinal string array as datasource:
But i think my control consumes more than needed resources because it simply destroys column and row definitions and recreates them. Is there any simpler way to implement that control?
You don't need to create a custom control to do that for you... you can use a standard DataGrid. There have been a number of questions on displaying dynamic data in a DataGrid. Please take a look at some of these posts:
How do I bind a WPF DataGrid to a variable number of columns?
DataGridColumn Binding with Dynamically Generated Data
Visualizing 2D Data in a Table
Displaying multidimensional data in WPF
I have a treeview right now with a templateselector. Basically each tree node on the root is a "category" of some type of data and each child node under those are displayed in a specific way (via the template selector).
This allows me to show different data in a single control easily just using binding. My problem is that it's not working out so well visually. I would like to have a grid style (ListView.GridView) under each root node.
I was looking at ListView grouping but is it possible to define different columns for each group? Since I doubt that is possible, what are some options? I would like to allow the user to expand and collapse the groups just like a treeview but see a GridView under each node with scroll bars, etc.
I don't think that ListView supports different headers in groups. It's just grouping of rows. Looks like you're going to have to create a new ListView under each tree node. You might try a data grid. In WinForms you can bind to multiple tables and the grid will group by table which can be expanded and collapsed which would in effect show different columns. If you're using MVVM (I assume some collection or hierarchy model) I have no idea how you'd accomplish that with a data grid.
You may achieve what you want relatively simple if you adopt the MVVM architecture.
Each node on the tree is of a certain type (ViewModel). Each data type would be bind to a specific View. Each View can be a ListView with any columns you want.
I recommend you read about MVVM and adopt it in order to achievewhat you need. I found that the adoption of MVVM leads to applications with a much cleaner architecture and code.
Silverlight 4 now provides controls to handle Drag and Drop actions. All the Target Controls seem to inherit from DragDropTarget Like so
public class MyControlDragDropTarget : DragDropTarget<TItemsControlType,TItemsContainerType>
.
.
.
A number of controls have pre-defined DragDropTargets including the DataGrid, ListBox, Panels
Which is all very well, but I want to drag and drop from a grid not a datagrid, and there is no pre-defined one for a normal grid.
I actually want to drag a given row from the grid, but without a Container Type for a Grid I cannot work out how to define a DragDropTarget control for the grid.
Only way I can think is instead of using a grid - I use a listbox (for which there is a DragDropTarget) and then place a StackPanel or Grid in each row (which has one row of 'n' columns)
Anyone got any ideas
Ta in advance
A "normal grid" is simply another form of panel, there is no need for specialised DragDropTarget for the Grid, the existing PanelDragDropTarget is sufficient for a "normal grid".
Its important grasp that the Grid does not support the concept of "rows containing cells containing UI elements". The rows and columns of a Grid are entirely equal and are defined purely for layout purposes. UIElement children of a Grid are laid out entirely independently of each other, there is no concept of a set of values belonging to either a column or a row that can be moved or operated on as a group (like picking up a row and dragging it).
Sounds like you have already got an answer for yourself, use the ListBox instead.
BTW, DragDropTarget isn't provided by Silverlight 4 but rather the Silverlight Toolkit. This is an important distinction because the current quality band assigned to DragDropTarget is "Experimental". You need to think carefully about this if you want to use such code in some production release of your own.
In my gridview I need to aggregate subrows into each row, something like in p2p emule/amule application where you can do double click to each file you are downloading and then under it you can see the parts of the file from where you are downloading.
Is it possible in WPF?
Thanks.
You could do a few things:
Add some container (ie: another Grid or a StackPanel) to the Grid row. This would let you add multiple objects to the grid row. On your "double click" event, you could change the visibility to show those objects.
Use a TreeView with a HierarchicalDataTemplate, and treat this as hierarchical data. This is most likely the more "correct" approach. The Displaying Hierarchical Data sample on MSDN walks through the process of this.