How to bind to a StaticResource with a Converter?

2019-01-23 11:10发布

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

2条回答
地球回转人心会变
2楼-- · 2019-01-23 11:30

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

查看更多
Fickle 薄情
3楼-- · 2019-01-23 11:33

Assuming that instead of Value= you'll use Source= and both resources are available I don't see a reason why it would not work.

查看更多
登录 后发表回答