How to bind to a StaticResource with a Converter?
Asked Answered
A

1

40

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}}?

Aerodyne answered 18/5, 2013 at 10:40 Comment(0)
D
72

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

Defrock answered 18/5, 2013 at 11:48 Comment(1)
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!Bordereau

© 2022 - 2024 — McMap. All rights reserved.