How do you apply a ValueConverter to a convention-based Caliburn.Micro binding?
Asked Answered
H

1

8

How do you apply a ValueConverter to a convention-based Caliburn.Micro binding? or do you need to use the {Binding} syntax?

I know I could do this

<TextBlock
    Text="{Binding Foo, Converter=fooToBarConverter}" />

but how do I apply that custom converter if I am using Caliburn.Micro's convention over configuration, like

<TextBlock
    x:Name="Foo" />

Thanks,

Harmonia answered 5/7, 2011 at 11:8 Comment(0)
D
5

You need to replace the ConventionManager.ApplyValueConverter func. By default it only does athe bool => Visibility conversion. Also, you can replace the ApplyStringFormat func for conventional string formatting. Have a look in the ConventionManager to see how it works.

Darfur answered 5/7, 2011 at 11:13 Comment(2)
Cool - thanks. I'd seen the SetBinding called this, but hadn't joined the dots in terms of needing to write my own...Harmonia
So, presumably I'd want to store the default boolToVis func somewhere, create my own ApplyValueConverter, then restore the default one after the VM completes binding to the View. Is that a reasonable approach? Not sure I'd want to leave my very specific IVC lying around as the default, tbh...Harmonia

© 2022 - 2024 — McMap. All rights reserved.