开发者

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

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.


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...


{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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜