user10101
user10101

Reputation: 1764

Binding instance as resource

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}}

Upvotes: 1

Views: 604

Answers (2)

dowhilefor
dowhilefor

Reputation: 11051

What might work is to write a custom markup extension. This should be a good reference.

But besides that, you can't "predefine" markups like that. Depending on your scenario, you might can put some of these into a datatemplate, which you can reuse.

Upvotes: 2

brunnerh
brunnerh

Reputation: 185410

You cannot declare a Binding in a resource dictionary, i doubt that this can be made to work using resources.

Upvotes: 0

Related Questions