Search code examples
wpfbindingmultibindingstaticresourceimultivalueconverter

WPF Compact this XAML which assigns static string to binding


There may not be any practical use of what I want to do, but just to satisfy my curiosity can we compact the 2nd binding in the following XAML into 1 line

<TextBlock>
    <TextBlock.Text>
        <MultiBinding Converter="{StaticResource MyConverter}">
            <Binding Source="{StaticResource One}"></Binding>
            <Binding>
                <Binding.Source>
                    <sys:String>2</sys:String>
                </Binding.Source>
            </Binding>
        </MultiBinding>
    </TextBlock.Text>
</TextBlock>

StaticResource One gives me "1" and MyConverter just concatenates all values it gets. What I am looking for is some way to express the 2nd binding in a compact format like the 1st binding.


Solution

  • I'm assuming there's some reason you don't want to define a second static resource called Two and then use the same syntax as with One...

    You should be able to:

    <Binding Source="2"/>
    

    Since Source is just an Object, this should assign the string "2" to the Source. Haven't checked though as I'm on linux at the moment.