What is the WPF analogy for the CSS em unit?
相关问题
- VNC control for WPF application
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
Unfortunately, there is no equivalent in WPF of the em unit. All your font sizes, etc are always set in Pixels.
Here is what I did. Created a MarkupExtension that converts Font size to EM based on font assigned on Window.
I would like to thank http://10rem.net/blog/2011/03/09/creating-a-custom-markup-extension-in-wpf-and-soon-silverlight
and
http://tomlev2.wordpress.com/tag/markup-extension/
for providing required knowledge.
Sample Usage
em size is the width of the uppercase letter M in the current font, there is no font-dependent sizing method in Wpf
Btw, WPF uses "device independent pixels" that are always 1/96 of an inch (because that's one pixels on today's monitors) so:
Those are extremely inaccurate on monitors because almost all monitors report a 96DPI resolution and ignore the real pixel size, but are very useful when printing.
AFAIK, there isn't one right now. But you can make your desire for this known here.
One alternative (and I don't know if this is possible either) would be to measure how big the desired font is, then take that as your "ems" unit, then scale using those "units" instead.
seems to be more or less the 1.2em alternative.