After constructing a Grid and adding Rows and Columns to it, how can modify the dimension of each Cell. I am not able to locate any property that would help me to achieve this.
As additional note, I am adding TextBlocks to each of the cell.
You can change the column width and row height within your ColumnDefinition and RowDefinition tags, or if you wish to have the cells in a less uniform arrangement you can set the ColumnSpan (might be ColSpan, it's been a while!) and RowSpan properties of each cell to create cells that span more than one row or column.
Do you want modify cells dimensions at runtime? If yes take a look at GridSplitter.
Related
I have a WPF datagrid where certain rows will be disabled. In addition to disabling the cell contents, I'd like to present to the user some text that overlays the row with an explanation such as "Row disabled due to ...". Basically the same effect of having a label control with a lower z-order sitting directly in front of the datagrid row's cells.
If cell text spillover was possible (like in Excel), I could create a text column of 0 width with the message, then let the message runover through the neighboring cells. But to my knowledge this type of text spillover isn't possible in the datagrid.
If your rows have fixed height, you could add a another transparent datagrid on top of the other datagrid. The transparent datagrid would have one column which would show the disabled explanation. Simple but hacky solution.
The proper way would be to use adorners.
My DataGrid is bound to a collection which can not change in run-time.
I wanted to ensure that when resizing the DataGrid columns the total width of the columns won't be
longer than the DataGrid width, so that no column will disappear and no horizontal scroll will appear, never find an answer to that.
So I wanted to no if there is a way that i can bind my DataGrid width to the total width of his columns so i can make the columns unresizeable and still have the columns width to "Auto" so no data will be missing while the columns is not resizeable?
Or the first option which i didn't find - limit the resize of the columns so their total width wont be longer?
Thank's a lot and please no Code-Behind soluton.
This seems close to some other questions I've seen out here, but not close enough...
I have a grid with three rows. The first row holds a custom grid that I want to have as much space as possible. I set its Height to "*". The second row is a row of buttons; it is "Auto". The third row is a user control that contains another custom grid that has an unpredictable number of rows (none at design-time, filled in at run-time).
If I set the third row to "Auto", it doesn't get any space at all. I need to understand what I have to do after I load the third-row's grid to make it then figure out what "Auto" should be. Or, if "Auto" doesn't apply, how else do I get the third row to take up Just Enough space?
Does my custom grid have to fire something like a resized event after it is loaded?
You shouldn't have to do anything
If the 3rd row's Height is Auto, it will resize according to the size of it's contents. If the size of the contents change at runtime, so will the size of the Row.
You can also set limitations on the Row's Height by setting MinHeight and MaxHeight on the 3rd Row so it doesn't get smaller or larger than a specified height.
Cells will collapse to fit their contents. If the contents don't have any specified size then the cell will collapse to nothing. I'm guessing for your middle row the buttons have fixed sizes, so the row collapses to the size of the buttons, but your third row has nothing with a fixed size so it collapses to nothing. Try giving your third row a fixed size either for the whole row or for each row in the contained grid.
I have a DataGrid with a custom theme. Right now, if I resize a column and make it wider, it tries to squeeze other columns to make space for this column.
Instead, is it possible to increase the width of the entire DataGrid with the increase in width of a column. It's OK if it shows a horizontal scrollbar at the bottom.
EDIT: Just to clarify, each column has a MinWidth set to it. So if the overall width > window width, I see a scrollbar. But in cases where I have a datagrid <= window width, and I expand one of its column, the width of the datagrid should theoritically increase at the point when the other columns have shrunk to their MinWidths. At that point, instead of letting the DataGrid grow in width, it doesn't let me expand the column any further. Instead, I want the DataGrid to expand and accommodate the increased space.
It sounds like one of your columns has a Width="*", which means that column is assigned to all remaining space and grows/shrinks as needed instead of letting the DataGrid grow/shrink as requested and showing it's HorizontalScrollBar.
The datagrid's default behaviour is the one you need! If your Datagrid is not showing a horizontal scrollbar maybe because it's contained in a control that's constraining its width. Try to put it inside a Grid, and be sure that you haven't set the 'Width' property of any control (including the Window) that is containing it.
that's what column's MinWidth is designed for. Just set it for the columns, which you don't want to shrink. to limit the max width of the grid use the ScrollViewer:)
Does anyone know how to draw a line between two items in a grid? I would normally use a canvas but it does not provide the layout I want.
The grid is the ItemsPanel of an ItemControl object.
Thanks,
Adam
You have to do following things, Suppose you have three columns in the grid and one item is in the first column and second item is in the third column and you have to draw line between them. and I am supposing that all the columns of the grid has same width.
Write style for the button which only contain the line.
now set the left margin and right margin of the line ( which will be the button and style of the button , you have created as I have mention above), to the half size of the columns width, and set the columnSpan of the line button to 3.
Hope that will help.