views:

1731

answers:

14

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?

+1  A: 

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.

Brad
+3  A: 

Include curly braces in the content of a control.

<Button Content="{}{This is not a markup extension.}"/>
Brad
+1  A: 

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">...
Brad
A: 

Insert double quotes in content:

<Button Name="Button"
        Background="AntiqueWhite"
        Content="{}{Background=&#0034;AntiqueWhite&#0034;}"/>
Brad
+5  A: 

A new feature of WPF delivered with 3.5 SP1 is the ability to format your string while binding. It eliminates the useage 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>
ArielBH
A: 

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.

Brad
A: 

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.

Brad
A: 

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.

Brad
+7  A: 

Debugging WPF binding. Adding tracing for binded 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

ArielBH
A: 

The property is BorderThickness. No matter how many times you type BorderWidth, it's not going to work!

Brad
+2  A: 

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.
Brad
A: 

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)
Brad
+1  A: 

Provide a unique row or column for a GridSplitter to ensure that it is not hidden by other controls and behaves as expected.

Brad
A: 

Set a property in Code Behind to a DynamicResource:

Border_Toolbar.SetResourceReference(BackgroundProperty, "Brush_ToolbarBackground")

Brad