Louis
Louis

Reputation: 725

How to supply a string literal value as a binding in WPF

EDIT:

My former question also referred to commands, but as pointed out in a comment below, it was unnecessary and added noise.


This is more a XAML syntax question, so it is probably trivial. I would like to know how to pass a string literal as a value for a binding in WPF.

If the value is already known from the context in XAML, may its value simply be directly assigned to the binding, instead of using paths and other means? If so, what would the syntax be in that case?

<MultiBinding.Bindings>
    <!-- First binding, a textbox  -->
    <Binding  RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type TextBox}}"/>
    <!-- Second binding, I want to pass a string as is, for instance, "Description" -->
    <!-- The proper syntax for the line below is what I am after -->
    <Binding Value="Description"/>
</MultiBinding.Bindings>

Upvotes: 6

Views: 4219

Answers (1)

brunnerh
brunnerh

Reputation: 185280

It's

<Binding Source="Description"/>

Source can be any type, so in attribute syntax that is interpreted as a string, if no Path is specified a binding's value is the source.

Also that is a multi-binding, i would not talk about command parameters as that is irrelevant to the matter...

Upvotes: 17

Related Questions