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
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>
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.
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">...
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.
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.
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.