Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent system constants in XAML (like double.MaxValue)

Tags:

constants

xaml

What is the xaml equivalent of MyProperty = double.MaxValue? I'm afraid I'll need to use something like MyProperty="{x:Static sys:Int32.MaxValue}", but not sure, and can't find the equivalent for double. Thanks.

like image 447
Mike Avatar asked Jan 05 '10 00:01

Mike


2 Answers

Found:

add this in the namespaces section of the control to access System library:

... xmlns:sys="clr-namespace:System;assembly=mscorlib" ...

then, to set Maximum property of MyControl control in ctr namespace:

<ctr:MyControl Maximum="{x:Static sys:Double.MaxValue}"/>

Edit:

{x:Static sys:Double.PositiveInfinity}

works too, but I suspect it is not appropriate to use it in this context, it seems to be reserved for evaluation like if (x==Double.PositiveInfinity). Experts can elaborate...

like image 153
Mike Avatar answered Oct 13 '22 18:10

Mike


{x:Static sys:Double.PositiveInfinity}

could be useful in case you have say some control setting MaxWidth to some value and you want to reset it via XAML at some ancestor

This is because double.PositiveInfinity is the default value (not set) forMaxWidth/MaxHeight`.

I found this useful with Silverlight Media Framework to hide/show the video area (to just hear the audio). See relevant notes near the bottom of:

How to hide the video area of the Silverlight media framework player

like image 22
George Birbilis Avatar answered Oct 13 '22 17:10

George Birbilis