Recently I discovered WPF supports different measurement units in XAML. Besides default DIPs, there is also support for pixels, inches and centimeters (as far as I know). This allows designer to write XAML such as this:
<Canvas>
<Line X1="0cm" X2="3cm" Y1="1cm" Y2="3cm" Stroke="Black"/>
</Canvas>
However, you cannot bind these values. Imagine we have a ViewModel with Dimension property which is a String, for example "7cm". Following won't work:
<Button Width="{Binding Dimension}">Test</Button>
FormatException gets thrown. Similarly, when creating a FrameworkElement
in code-behind, like this:
Canvas1.Children.Add(new Button() { Width = "3cm", Content = "Test"});
Compilation fails because exception is thrown in constructor/wherever you try to create the control.
I wonder:
- Is it possible to use natural units (in my case metric - centimeters) in code-behind?
- How?
- Is there a complete list of units WPF/XAML supports?
EDIT:
Here is a link from comment below, which resolves this question:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width.aspx