Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 919
Louis Avatar asked Jul 18 '13 21:07

Louis


1 Answers

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

like image 109
H.B. Avatar answered Oct 19 '22 22:10

H.B.