I was fooling around with margins and padding and found that a negative value was acceptable and gives a nice effect in appropriate circumstances. For instance, if you have a border with a filled object and you want the filled object color to overrun the border. Anyone have any others?
15 Answers
Debugging WPF binding.
Adding tracing for bound properties:
<Window …
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"/>
<TextBlock Text="{Binding Path=Caption,
diagnostics:PresentationTraceSources.TraceLevel=High}"…/>
You will get in the output window much details about the binding:
PropertyChanged event from SomeObject (hash=1)
SetValue at level 0 from SomeObject (hash= 1) using RuntimePropertyInfo(Field):
'False'
TransferValue - got raw value 'False'
TransferValue - using final value 'False'
//EDIT More Info here.
Ariel

- 3,741
- 12
- 49
- 72

- 1,991
- 3
- 22
- 38
-
more info link is dead – mike May 20 '21 at 23:35
A new feature of WPF delivered with 3.5 SP1 is the ability to format your string while binding. It eliminates the usage of IValueConverter
for such common scenarios.
Here are some examples to get you going which I copied from this blog post
<TextBox Text="{Binding Path=Double, StringFormat=F3}"/>
<TextBox Text="{Binding Path=Double, StringFormat=Amount: {0:C}}"/>
<TextBox Text="{Binding Path=Double, StringFormat=Amount: \{0:C\}}"/>
<TextBox>
<TextBox.Text>
<Binding Path="Double" StringFormat="{}{0:C}"/>
</TextBox.Text>
</TextBox>

- 3,741
- 12
- 49
- 72

- 1,991
- 3
- 22
- 38
Visibility
is a three-state System.Windows.Visibility enumeration:
- Visible - The element gets rendered and participates in layout.
- Collapsed - The element is invisible and does not participate in layout. Effectively giving it a height and width of 0 and behaving as if it doesn't exist.
- Hidden - The element is invisible but continues to participate in layout.

- 37,266
- 20
- 108
- 140

- 1,187
- 3
- 23
- 44
Set a debug style that provides visual cues:
<Window.Resources>
<Style x:Key="DebugGrid" TargetType="Grid">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="ShowGridLines" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid Name="Grid"
Style="{StaticResource DebugGrid}"
Background="Black">...

- 1,187
- 3
- 23
- 44
Include curly braces in the content of a control.
<Button Content="{}{This is not a markup extension.}"/>

- 1,187
- 3
- 23
- 44
IsMouseOver
and IsMouseDirectlyOver
are different events. IsMouseOver
responds to all mouse movement within a control and it's children. IsMouseDirectlyOver
responds only if the cursor is over the control itself. For instance, if you have a label contained within a border, the IsMouseDirectlyOver
event for the Border only fires if the cursor is over the Border itself but NOT over the contained Label.

- 3,741
- 12
- 49
- 72

- 1,187
- 3
- 23
- 44
-
1Not sure if your answer answers the original question but it did clarify what I was looking for. (+1) – jpierson Feb 25 '13 at 20:10
Calculate the available real estate as a percentage:
<Grid.RowDefinitions>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="0.25*"/>
<RowDefinition Height="0.25*"/>
</Grid.RowDefinitions>
EDIT:
This works but is not indicative of how the * parameter functions. This:
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
provides the same functionality. If you want something other than equal height rows you can use:
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
<RowDefinition Height="3*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
which will divide the available height by 10 and maintain the relative height of each row. Alternatively, the values could be 0.1, 0.2, 0.3, and 0.4 or any proportional value.

- 1,187
- 3
- 23
- 44
The property is BorderThickness. No matter how many times you type BorderWidth, it's not going to work!

- 1,187
- 3
- 23
- 44
Padding
and Margin
are entered using comma-delimited syntax and are of type Thickness. They can be entered as:
- Padding="5" (Padding is 5 on all four sides)
- Padding="5,10,15,20" (Padding is Left: 5 Top: 10 Right: 15 Bottom: 20)
- Padding="5,10" (Padding is 5 on the Left/Right and 10 on the Top/Bottom)

- 3,741
- 12
- 49
- 72

- 1,187
- 3
- 23
- 44
-
You can also delimit them by simple space. Padding="5 10 15 20" – Andrew Mikhailov Feb 13 '15 at 13:13
Provide a unique row or column for a GridSplitter
to ensure that it is not hidden by other controls and behaves as expected.

- 3,741
- 12
- 49
- 72

- 1,187
- 3
- 23
- 44
Decide dimensions of one control based on another at runtime.
<... Width="{Binding ElementName=referenceElement, Path=ActualWidth}" ../>
This can be done with Height/MaxHeight
etc. too.

- 3,741
- 12
- 49
- 72

- 22,194
- 16
- 64
- 99
Insert double quotes in content:
<Button Name="Button"
Background="AntiqueWhite"
Content="{}{Background="AntiqueWhite"}"/>

- 1,187
- 3
- 23
- 44
Set a property in Code Behind to a DynamicResource:
Border_Toolbar.SetResourceReference(BackgroundProperty, "Brush_ToolbarBackground")

- 3,741
- 12
- 49
- 72

- 1,187
- 3
- 23
- 44
A Grid
with the Background
left as default or set with a Transparent
brush will not fire the IsMouseOver
event unless the cursor is over a containing control. To ensure the event is fired over the Grid
itself, simulate Transparency
by setting the Background
to the container Background
color.

- 3,741
- 12
- 49
- 72

- 1,187
- 3
- 23
- 44
-
2not true for the Brushes.Transparent background as of .net 4.0 at least (I don't know for previous versions), but true for the default background which is set to "{x:Null}" and does not behave like Brushes.Transparent. i.e.: if you want to trap the mouseDownEvent on a transparent-background control, you have to explicitly set its background to Brushes.Transparent – David Feb 11 '11 at 14:28
A control with the background set to Transparent will NOT fire the IsMouseOver or IsMouseDirectlyOver events. For example, if a Border Background is set to Transparent but the BorderBrush=Blue and the BorderWidth is <> 0, the MouseOver events will fire while over the Border itself but not while over the interior of the control.

- 1,187
- 3
- 23
- 44