How to set grid cursor can work in entire grid? - wpf

I have a grid with 2 rows * 2 columns, and put a TextBlock in left-up cell(row=0, column=0).
then I set Grid.Cursor = "Hand" in XAML. the hand-cursor displayed only when mouse over TextBlock. But I want to display the hand-cursor in entire grid.
How to do it?

Set the Background of the Grid to transparent.

The Cursor is only applying to the content area of the grid. Thus to get the cursor across the whole grid, fill it in.
This can be shown, by changing what grid cells the TextBlock is positioned in.

Related

WPF: Set Control Height to Fill Grid Row Height

A WPF Grid control with 3 row and 3 columns. The Height of the Row in question is set to Auto. In the first two cells I have two controls with dynamic heights. In the third cell, I have another control I want to be automatically set to stretch within the Grid cell. I have tried VerticalAlignment="Stretch", but that simply sets Grid Row Height equal to control's height. What are my options here?
Not sure what kind of control you are using in Cell 3, but most of the WPF controls will automatically stretch to fit inside the Grid cell. The row height of your grid will be set by the height of the controls in Cells 1 and 2.
If you are using some kind of custom control where the default behavior for height is different, you can set Height="Auto".
If that doesn't work either, you can do a data binding to get the actual height of the control in either cell 1 or 2. Set the Height property of your control in Cell 3 to the following:
Height="{Binding ActualHeight, ElementName=MyControlNameFromCell1, Mode=OneWay}"
EDIT
Another way that might be more robust is to do a data binding for the Height of the row. So instead of using "Auto" for the height of the row, use the data binding shown above.

Expander with GridSplitter

I've a grid splitter before to the expander(which exists in the right side of a wpf window) and when i was running the app i need to use grid splitter to see more data from expander after its expanded, but the problem is when i was drag splitter i'm getting full view of my expander irrespective of original width but after click on expander to collapse it won't go to its original position by maintaining the splitter dragged width. So any one help me how can i send back expander to its original position.
Thanks,
#nagaraju.
Once you have used the splitter the grid column widths will no longer be 'auto'.
One solution is to respond to the collapsed event of the expander and reset the width of the first column to auto using column.Width=GridLength.Auto;
As you are resizing the contents of the Expander it may make more sense to place the GridSplitter inside the Expander, and on the outside you just have a normal Grid which makes the cell where the Expander is size to content.

Data Grid View and Vertical scrollbars issue

I realized something annoying when using a data grid view control. When I try to set the cell's height by setting the RowTemplate height property to fit more records on the grid, the vertical scroll bar stops acting nicely and the grid doesnt display all the records (it only shows the records that fit on the available space plus one extra record!) until you resize the columns or something like that! But if I set the AutoSizeRowsMod property to AllCells the grid displays all the records, however the cell's height is now too big for me!
Is there a way to control the cell's height and still show all the records on the DGV? Does it even make sense that it's behaving this way?
Thanks

WPF, ShowGridLines equivalent for wrap panel

I need to display a 1 pixel wide border around all wrap panel cells, kinda like excel grid. Unfortunately the wrap panel does not implement the grid ShowGridLines property. I can't put a border inside every cell because adjacent cells will have a 2 pixel border instead of 1 pixel.
Since the wrap panel arranges it's layout dynamically and does not expose it's properties I can't evaluate the correct value for a border inside a cell. Any workaround possible?
There is no way to show grid lines because it's just not a grid. Even in a WPF grid control, you have very little control over the appearance of lines: How can I change the color of the gridlines of a Grid in WPF?. They're really just for debugging. The workaround is to put a border inside each cell that only has thickness on the bottom and on the right: BorderThickness="0,0,1,1"

How to set up a Windowsforms databound DataGridView such that only x rows are visible?

I need to set up a windows form DataGridView, programmatically bound to a list, such that only 6 rows are visible to the user (i.e. the grid's height is only 6 cells) and a scroll bar appears when there are more than 6 elements in the bound list. All the rows need to be of the same height. Is there a configuration of properties that does this or do I have to manually set the height of the DataGridView so that only 6 rows would be visible?
Set the size of the control such that at most 6 rows are visible, and set the Scrollbars property so that the vertical scrollbar appears as needed (to Vertical, or Both if you need a horizontal scrollbar as well).
If I understand your question correctly, you're wanting to use paging on the datagridview. If this is correct try this and this. It's a bit convoluted though.

Resources