Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Last active March 15, 2019 08:53
Show Gist options
  • Select an option

  • Save xgenvn/1e0acc7fbc11ca98b88ee5ed9f269d62 to your computer and use it in GitHub Desktop.

Select an option

Save xgenvn/1e0acc7fbc11ca98b88ee5ed9f269d62 to your computer and use it in GitHub Desktop.
50 shades of binding XAML/WPF

Binding elementName

Binding Path=<Prop>, ElementName=<>

Binding relative source ancestor

<Binding>
  <Binding.RelativeSource>
    <RelativeSource
      Mode="FindAncestor"
      AncestorType="{x:Type typeName}"
      AncestorLevel="intLevel"
    />
  </Binding.RelativeSource>
</Binding>

Binding relative self

{Binding RelativeSource={RelativeSource Self},
               Path=Height}

Binding parent

Width="{Binding RelativeSource={RelativeSource Self}, Path=Parent.ActualWidth}"
Height="{Binding RelativeSource={RelativeSource Self}, Path=Parent.ActualHeight}"

Binding parent in

{Binding Path=propertyOfControlTemplate, RelativeSource={RelativeSource Mode=TemplatedParent}}

is similar to

{TemplateBinding Path=propertyOfControlTemplate}

but standard Binding is preferred

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment