WPF, ShowGridLines equivalent for wrap panel - wpf

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"

Related

WPF Grid Lines show across childrent element with span > 1

Are there any way to make grid to not show over grid children?
I mean, I want grid lines to be visible, but when a children has rowspan or columnspan over 1, I want it to hide the grid lines.
I tried setting the children (it's a label) opacity to 1 but it didn't work.
Any help will be welcome.
No there is not. From MSDN:
Only dotted lines are available because this property is intended as a design tool to debug layout problems and is not intended for use in production quality code. If you want lines inside a Grid, style the elements within the Grid to have borders.

WPF Ellipse why can I not add a grid?

I have a WPF application. I am trying to create a ellipse toggle button. I wanted to have a textbox in the ellipse with two images next to each other below the textbox. In my other buttons I have added a grid with two rows to achieve this.
However it doesn't like it when I try to add a grid to an ellipse. "The type ellipse does not support direct content". What does this mean? Is it possible to do what I wish?
This particular error really couldn't be too much clearer:
The type Ellipse does not support direct content.
The Ellipse Shape is not a ContentControl. Therefore, it does not have a Content property. This means that you cannot add any content to it.
What you can do is to add a Grid with no columns or rows defined and add your Ellipse into the Grid. Then you can overlay other UI elements in front of the Ellipse, which may appear as if they were inside it.

WPF: How can i scale to fit the content?

It gets basicaly to this:
I have a canvas container (x:name="Container" - to reffer later to), with some other controls(e.g. I have a Button 30x60 in size) and I want to scale the Container to fit the button, without having to resize anything. (just using scaleTransform)
If I set a slider binded to the Container Scale, I can slide it to fit the button, but the value is 1.1343 and I want to be able somehow to compute this value programatically, because all the controls inside Container are of different sizes, and resizable in adition.
The question is: is there a way to scale the Container so that a Control from the container is displayed on the entire Container surface? Also the position will have to be adjusted, so that the scrolling vierew of the Container should be positioned over the control, but that is done already.
Thank you in advance,
Daniel
Use Grid as the container. Any control placed inside of the Grid will directly fill the whole Grid, and its size (the width and height) will match the size of the Grid.
It seems when you add a user control using a grid as a container, the usercontrol, which comprises a set of labels and an array of buttons will not align to the top but arranged somewhere in the middle.

How to place a long Grid in a WPF Layout Container?

When I place a Datagrid in a WPF Grid Layout container, the datagrid lengthens the Grid Layout.
I want it to occupy only the space available on screen.
Make sure your Grid.ColumnDefinition or Grid.RowDefinition's Width or Height is not set to Auto. If you set it to a fixed size or a star size then the row/column should not resize.
If you're still having problems a code sample would be useful.
You should place your Datagrid into a ScrollViewer, and the ScrollViewer into your Grid cell.
the grid is placed inside a tabitem.
I tried the scrollviewer. but the only thing that happens:
the scrollviewer gets as large as the too long datagrid.
as the tabitem can vary in height, I would rather not like to specify a fixed height for the grid.

adjust border on one specific side

I'm using a controlTemplate of the ListBox to show a collection.
I want to display all the items with a border like in a grid (all lines same size).
When I give every listBoxItem a border, the line between 2 items has a double size.
(made from the bottom border of the first item, and the top border of the second item)
So the question is:
Can I set/hide the border on a single side of an item? (like 'border-top' in css)
The border property is a thickness, just like margin and padding, so you can do Border="2,0,2,2" to get a border of 2 everywhere except the top.

Resources