Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass a constant value for 1 binding in multi-binding?

I have a multi-binding like

<TextBlock>     <TextBlock.Text>         <MultiBinding Converter="{StaticResource myConverter}">             <Binding Path="myFirst.Value" />             <Binding Path="mySecond.Value" />         </MultiBinding>     </TextBlock.Text> </TextBlock> 

And I want to pass a fixed value e.g. "123" to one of the two bindings above. How can I do that using XAML?

like image 237
Nam G VU Avatar asked Jul 27 '10 04:07

Nam G VU


People also ask

What is binding path in WPF?

Binding path syntax. Use the Path property to specify the source value you want to bind to: In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as Path=PropertyName . Subproperties of a property can be specified by a similar syntax as in C#.

What is MultiBinding in Xamarin forms?

In this article Multi-bindings provide the ability to attach a collection of Binding objects to a single binding target property. They are created with the MultiBinding class, which evaluates all of its Binding objects, and returns a single value through a IMultiValueConverter instance provided by your application.

What is WPF MultiBinding?

Multibinding takes multiple values and combines them into another value. There are two ways to do multibinding, either using StringFormat or by a converter. The StringFormat is simple compared to a converter, so we will start with that first. <TextBlock> <TextBlock.Text>


1 Answers

If your value is simply a string, you can specify it as a constant in the Source property of a binding. If it is any other primitive data type, you need to define a static resource and reference this.

Define the sys namespace in the root of the XAML to point to System in mscorlib, and the following should work:

<TextBlock>   <TextBlock.Resources>     <sys:Int32 x:Key="fixedValue">123</sys:Int32>   </TextBlock.Resources>   <TextBlock.Text>     <MultiBinding Converter="{StaticResource myConverter}">       <Binding Path="myFirst.Value" />       <Binding Source="{StaticResource fixedValue}" />     </MultiBinding>   </TextBlock.Text> </TextBlock> 
like image 198
Noldorin Avatar answered Dec 21 '22 10:12

Noldorin