Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this in code behind by applying the same conversion the XAML-parser uses, you do not need to reimplement this logic if you don't mind passing around strings:</p> <pre class="lang-cs prettyprint-override"><code>button.Width = (double)new LengthConverter().ConvertFrom("2cm"); </code></pre> <p>The XAML-parser uses <a href="http://msdn.microsoft.com/en-us/library/cc645047.aspx" rel="noreferrer">TypeConverters</a> to convert strings to the needed values, in the <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.width.aspx" rel="noreferrer">documentation page of the <code>Width</code> property</a> you can see that it has a <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverterattribute.aspx" rel="noreferrer"><code>TypeConverterAttribute</code></a> specifying that a <a href="http://msdn.microsoft.com/en-us/library/system.windows.lengthconverter.aspx" rel="noreferrer"><code>LengthConverter</code></a> should be used. This attribute can be used to locally override how a property should be handled, but it can also be applied at class level, so if an <code>Employee</code> class has this attribute specifying that an <code>EmployeeConverter</code> should be used said converter will be the default for properties of type <code>Employee</code>.</p> <p>I am a bit surprised the binding does not apply this type converter, but using it inside an <code>IValueConverter</code> would be simple enough, in fact you could create a <a href="http://msdn.microsoft.com/en-us/library/ee855815.aspx" rel="noreferrer">markup extension</a> which constructs an <code>IValueConverter</code> from a type converter to make it nicely generic.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload