0

I'm trying to set a double value to the FontSize property of the ListBoxItem control from code behind. I have noticed some really strange behavior. The value that I pass to the FontSize setter gets changed a little bit (rounded?) before being applied to the control. For example:

Font size before                 3.8730912208557129
New font size passed to setter   4.2251904227516865
Font size after assignment       4.22519063949585

Does anyone have a clue if this is standard Silverlight behavior or not? Maybe there's some sort of processing in FontSize setter to display fonts nicely? MSDN didn't reveal anything useful.

george.zakaryan
  • 960
  • 1
  • 6
  • 18
  • 2
    why does it bother you? – thumbmunkeys Sep 05 '14 at 08:17
  • I have some really complex logic with font sizes that's why it bothers me. In a couple of words, I need to check if a control's font size has changed or not. – george.zakaryan Sep 05 '14 at 08:19
  • 2
    For comparing floating points, you could use this technique with a reasonably big tolerance: http://stackoverflow.com/questions/17404513/floating-point-equality-and-tolerances I am not sure why the value in your case changes, but I guess, the font size is internally stored differently (float maybe?) – thumbmunkeys Sep 05 '14 at 08:23
  • 1
    Well, thanks for the hint. I can surely compare the values with a reasonably small epsilone. I just wanted to know the cause for such behavior. – george.zakaryan Sep 05 '14 at 08:25
  • 2
    Guess I will have to try something like Telerik JustDecompile to dig into the assembly and find out. – george.zakaryan Sep 05 '14 at 08:27
  • 1
    good luck :) If you find something out, I'd be interested too – thumbmunkeys Sep 05 '14 at 08:34

0 Answers0