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?
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#.
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.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With