I have a very long and repeating binding expression in xaml. Can I first define it in resource section and then refer to it using DynamicResource or StaticResource? Something like:
<SomeControl Visibility="{DynamicResource BindingToParentDataContext}">
The binding expression looks like:
{Binding Path=DataContext.SomeProperty, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SomeParentUserControl}}, Mode=OneWay, Converter={StaticResource booleanToVisibilityConverter}}
RelativeSource
,Mode
andConveter
in constructor. It` pretty straightforward. – SherikasherillAncestorLevel
is defaulted to -1, but you can`t set it with value less than 1 yourself. So just use another constructor and setAncestorType
directly after creatingRelaticeSource
. – Sherikasherill