0

The TextBlock.FontSize must be the product of

  • a dynamic resource FontSizeFactor
  • a static hard-coded value 32

How can I do this in XAML?

(With Binding, MultiBinding, Converter or whatever, but without code behind)

jeromerg
  • 2,997
  • 2
  • 26
  • 36

2 Answers2

0

Try this Math Converter You can do a lot of calculations in xaml by using this ValueConverter

Krishna
  • 1,956
  • 13
  • 25
  • I fear it doesn't work, as you cannot set a dynamic resource to a Binding Source – jeromerg Jun 11 '14 at 08:22
  • Sorry didnt think about that. But you can write a markup extension. Please see this question that was asked before. http://stackoverflow.com/questions/4805351/use-ivalueconverter-with-dynamicresource – Krishna Jun 11 '14 at 08:43
  • Thank you for your help! Unfortunately, the answer http://stackoverflow.com/questions/4805351/use-ivalueconverter-with-dynamicresource doesn't work at all... I spent an additional hour to test and understand what's going wrong, but the solution provided is simply wrong (see the comment I added to the answer). – jeromerg Jun 11 '14 at 11:10
0

Check whether the below solution meets your requirement. Note: The solution works for staticResource. Inside the convertor you can product the FontSizeFactor value and 32

<Window.Resources>
     <Clr:String x:Key="FontSizeFactor">2</Clr:String>
     <local:MyConverter x:Key="MyConverter" />
</Window.Resources>
   <Canvas>
       <TextBlock Text="siva" FontSize="{Binding Converter={StaticResource MyConverter}, 
                                    ConverterParameter={StaticResource FontSizeFactor}}" />
   </Canvas>
Sivasubramanian
  • 935
  • 7
  • 22
  • It doesn't work: DynamicResource cannot be set to ConverterParameter – jeromerg Jun 11 '14 at 10:41
  • ok, I will post another solution. before I Just want to make sure that, you want to bind the DynamicResource only one time right?? What i assume is you dont want to update the TextBlock's font size when the dynamic Resource value is changed. Correct me if I am wrong. – Sivasubramanian Jun 11 '14 at 11:04