How do you set the FrameworkElement.Width property to valueDouble, in code?

I am trying to set the width property of one of my controls to qualifiedDouble,
as described here on MSDN .
(Scroll down to the "XAML Values" section to see MSDN information on using qualified Double)

However, I want to know how to achieve this in code, not in XAML. UserControls created by the user are not bound to them by XAML for inheritance purposes. So I have to do all the XAML operations manually, using everything I can in C #.

Does anyone know how Double qualifications are achieved in code?

+3
source share
1 answer

What a coincidence, I should have done it earlier today. Skilled counterparts end up converting factors based on the unit you give him, but as part of it LengthConverter.

LengthConverter lc = new LengthConverter();
string qualifiedDouble = "10pt";

double converted = lc.ConvertFrom( qualifiedDouble );

Alternative

double original = 10.0;
double converted = original * 1.333333333; // px-to-pt conversion

This, for example, converts "10pt" to 13.3333333. You can also use the conversion factors that the article provides, but I prefer to use the above, as factors are built into the class.

Edited: In response to a comment about the lines ...

, . XAML, XAML, # VB. XAML , TypeConverter . FontSizeConverter , LengthConverter. ( FontSizeConverter.) GridLength, , "4 *" Width, "". , , .

, .

+5

Source: https://habr.com/ru/post/1715191/


All Articles