adjust border on one specific side - wpf

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.

Related

WPF Stretch Middle Content in DockPanel or Stackpanel

How do I stretch the content in the middle section of a Stackpanel or Dockpanel. I know that a dockpanel will stretch the last item but I need to stretch the middle item. I know that I could use a grid with * for the middle section but I want to be able to set the left and/or right items as collapsed depending on my window size.
You should still use a DockPanel with LastChildFill setted.
Your DockPanel will stretch the last element you put in it, not the last one according to view.
So you can put the element you want to stretch in the last position and use DockPanel.Dock="Top/Bottom/Right/Left" on others one.

WPF TreeViewItem Style individual borders

I need to create 3 styles for the items in a TreeView:
Style1 should show a border at the top of the item (full line, not only this item's content width)
Style2 should have no border, but a Red background (this is done already)
Style3 should show a border at the bottom of the item
The styles will be assigned in code behind according to some situation.
How do I define the borders in these styles?
Thank you!

ZIndex and silverlight

I have an image which constitutes the subject of a question and I want to place buttons on top of it for the user to click.
I have an object which positions a sprite (a rectangle with a background image which is transformed)
And I have an ItemsControl which positions the buttons using Margin.left and top. Like so
<Grid x:Name="imageGrid">
<local:spriteView Canvas.ZIndex="10" x:Name="QuestionImage" Sprite="{Binding QuestionImageSprite}" />
<local:ImageAnswers Canvas.ZIndex="50" x:Name="AnswersImages" Answers="{Binding answers}"></local:ImageAnswers>
</Grid>
I want AnswersImages to be positioned directly on top of QuestionImage but QuestionImage is pushing AnswerImages down and AnswerImages is also affecting the position of QuestionImage.
How do I stop them from doing that? Can I force them to be positioned absolutely within the ImageGrid
Remove the Canvas.ZIndex declarations. If your putting them both in a grid without specifying additional Column and Row definitions they will lay ontop of each other in the order they appear in the XAML

VisualBrush Visual Refresh Problem

I have a grid with two rows.
In the first row, I have a rectangle, fixed width and height, whose fill is a VisualBrush whose Visual binds to a tabcontrol's selecteditem.content, which resides in the grid's second row.
All works well - the rectangle displays a scaled down version of the SelectedItem's content in the TabControl. The problem is if I remove the current TabItem and add a different one, the preview doesn't change.
Any thoughts?
Chris

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"

Resources