UI Toolkit - Bind value to Size percentage?

Hello! I bound the size of one of my elements to an int variable in my code and I feel like it’s always putting it back to px even though I put it in percentage before manually… Is there anything I gotta do to set the size binding in percentage instead of pixels?

Thanks!

Hi @GalzZy the conversion from a primitive to a style value will use a similar path as what would happen using code, so it will always be a Pixel value. To get a Percentage value, you can either use a converter on the binding instance (note, the destination type of the converter itself must match the data type of the destination) or switch your data to a StyleLength.

Hope this helps!

Well I fixed my problem by creating a converter from int to StyleLength and then return Length.Percent(v) and it’s as easy as that :slight_smile:

Thanks!

1 Like