How to bind to a StaticResource with a Converter?

21,243

This works:

<TextBox Text="{Binding Source={StaticResource myStatic}, 
                        Converter={StaticResource myConverter},
                        Mode=OneWay}" />

Note that you have to bind one way, because the binding requires a path attribute otherwise. This makes sense, as otherwise the binding would have to replace the whole resource...

Share:
21,243
Ignacio Soler Garcia
Author by

Ignacio Soler Garcia

I am now acting as a delivery manager focused on the three main pillars of software creation: People, Procedures and Code working mainly with Javascript teams (React / Redux / Node) building applications 100% in the cloud with CI/CD, etc. I am open to proposals, let's talk. Previously I used to be an experienced technical leader commanding .Net technologies, passionate about Agile methodologies and a people person.

Updated on May 17, 2020

Comments

  • Ignacio Soler Garcia
    Ignacio Soler Garcia about 4 years

    I want to use a Converter to change the value of a StaticResource before assigning it to a property. Is there a way to simulate a Binding that will just set the value of the StaticResource after converting it?

    Something like {Binding Value={StaticResource myStatic}, Converter={StaticResource myConverter}}?

  • Marcin Tarsier
    Marcin Tarsier over 6 years
    For properties, which probably won't change at runtime from XAML side this Mode=OneWay isn't required, e.g. for Grid.Row. Anyway - I finally got ridden of magic numbers from XAML in favor of enums, thanks!