Setting local int variable's value to Int.MaxValue in xaml - xaml

I was wondering how I can set a local int variable's value to Int.MaxValue in xaml (which is in the ResourceDictionary in my case).
something like: (but something that works :) )
xmlns:s="clr-namespace:System;assembly=mscorlib
<s:Int32 x:Key"HelloWorld">{x:Static s:Int.MaxValue}</s:Int32>
EDIT:
#Ian:
Thank you :)
But how do I use the static resource as an int?
let's say if I have in my ResourceDictionary
<ResourceDictionary>
<x:Static
x:Key="HelloWorld"
Member="s:Int32.MaxValue"
/>
...
<blablalba TooltipService.ShowDuration="{StaticResource HelloWorld}"/>` <-- this does not work by the way
</ResourceDictionary>

This should do it:
<x:Static
x:Key="HelloWorld"
Member="s:Int32.MaxValue"
/>
Just in case it's not clear what's actually happening here, it's using a handy trick that a lot of people don't know about: although markup extensions like x:Static are normally used in attributes inside braces ({}) you can also use the element syntax for them. This is useful in situations like these where you want to use a markup extension, but the Xaml syntax expects an element. (It's most often necessary in scenarios involving collections, like this one.)
The one slight gotcha with using element syntax for markup extensions is that you no longer get to pass in constructor arguments. (Technically, constructor argument support was introduced in XAML 2009, which has been supported since .NET 4. However, it's only supported if you load Xaml via the new Xaml APIs. The MSDN documentation says that the new XAML 2009 features are not supported for compiled Xaml in WPF.) So you can only use this trick with markup extensions that offer default constructors, and which provide properties that can be used instead of constructor arguments. The StaticExtension provides a Member property that does the trick, so we're OK here, but be aware that sometimes, you'll be stuck due to the inability to call the appropriate constructor.
Note that as you type this in, the Xaml IntelliSense in Visual Studio will probably suggest StaticExtension, which is the real name of this markup extension. When you use the attribute syntax, it leaves off the Extension part, but with elements, it seems not to, for some reason. Either form is correct though - I'd go with what I've written here and not what IntelliSense suggests, because we're more accustomed to seeing "{x:Static ...}" in attributes than "{x:StaticExtension ...}" - again, both are legal, but idiomatically, we tend to leave off the Extension.

You were so close first time, just turns out you missed the 32 from Int32
<blablalba TooltipService.ShowDuration="{x:Static s:Int32.MaxValue}"/>
The other solution of adding a static resource seems a bit ridiculous - you're essentially creating a static resource as a wrapper around an existing static property...

The problem is that there is no class Int If you try with Int32 it works

As such.
<Button>
<ToolTipService.ShowDuration>
<x:Static Member="sys:Int32.MaxValue" />
</ToolTipService.ShowDuration>
</Button>

Related

What is the origin of $generalUtil in my atlassian-plugin.xml?

I'm studying the code of a custom Confluence plugin, which contains an atlassian-plugin.xml file that includes references to two variables $generalUtil and $helper, but I find no definitions of them whatsoever in the entire project. They simply work and it appears to me that they are magically instantiated out of thin air.
<web-item key="configtab" name="configtab" section="system.space.tools/addons">
<label key="myplugin.space.tools.addons.tab.label" />
<link>/spaces/myplugin-config.action?spaceKey=$generalUtil.urlEncode($helper.spaceKey)</link>
</web-item>
The $generalUtil must be an instance of com.atlassian.confluence.util.GeneralUtil, which also has a method urlEncode(). But where does this variable originate from?
What puzzles me even more is the $helper, which has a spaceKey field/method that I find in the code, but without any relationship to any kind of Helper class. The $helper also appears in a velocity template, but also without any definition of it. Any ideas where this stuff is documented?
generalUtil is documented here: https://docs.atlassian.com/ConfluenceServer/javadoc/7.11.6/
I think helper is https://docs.atlassian.com/ConfluenceServer/javadoc/7.11.6/com/atlassian/confluence/themes/GlobalHelper.html
They are injected into the Velocity context used to render that link.

What 'expression:' property in QML Item

I've inherited a collection of mostly undocumented QML code. I'm new to QML, and I'm struggling to understand this code. In particular, the construct
expression: "connected == false"
occurs frequently in various items, but I can't find any documentation on what this property does. It does not seem to be defined anywhere in the existing code collection, so I'm assuming it's part of QML, but I'm having no luck turning it up anywhere.
It looks as though all items using this construct are backed by C++ classes. However, "expression" is not defined as a QPROPERTY anywhere in the C++ code.
Nope, there's no such property in QML. You'll have to look into the QML file for the type that it's used in, or the C++ if it's declared there.

Loading Loose Xaml with custom controls on WinRT fails unless dummy DataTemplate exists

In ReactiveUI, I run this code at a certain point:
const string template = "<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:routing='using:ReactiveUI.Routing'>" +
"<routing:ViewModelViewHost ViewModel=\"{Binding}\" VerticalContentAlignment=\"Stretch\" HorizontalContentAlignment=\"Stretch\" IsTabStop=\"False\" />" +
"</DataTemplate>";
var theTemplate = XamlReader.Load(template);
On other platforms, this works great (the xmlns declaration is different of course), but on {WinRT / Metro / Windows Store}, this throws an Unspecified Error:
WinRT information: The type 'ViewModelViewHost' was not found. [Line: 1 Position: 253]
The Twist
However, if you include a dummy resource on the page:
<Page.Resources>
<DataTemplate x:Name="Foo">
<routing:ViewModelViewHost ViewModel="{Binding}" />
</DataTemplate>
</Page.Resources>
...then it works! What gives?
The "twist" makes me think this must be because the application does not have correct XAML metadata for the type being instantiated - rather than using reflection to resolve types in XAML files like WPF/Silverlight, WinRT uses code generation to resolve via the IXamlMetadataProvider interface (there's a decent description here; this sounds like what you're doing, see also the followup). Adding the reference forces this metadata code to be generated properly. If this is the case, you should be able to achieve the same effect by simply adding the type itself to the resources under some unused key, without the data template.
Have a look in your application's "obj" directory, Visual Studio generates a XamlTypeInfo.g.cs file to implement IXamlMetadataProvider. This should contain an entry for the type that is failing - in the case where you have added a dummy reference, there should be full details required to instantiate the type. Without this, I've found it's possible to have some reference to type type, but insufficient information - however this prevents the fallthrough behaviour (looking up the type in a dependent DLL which might have a custom metadata provider).
Other than adding a dummy reference to the library type in the final application itself, the only solution I found for this is to apply the Bindable attribute to the type. While this is supposed to relate to C++, I found this can be used in C# to force a type to always appear in the code generated for XAML type metadata.

TypeScript Intellisense works differently if I define Object in Different Ways

I am trying to convert some existing JavaScript code by using TypeScript, One example I am using is to create Highcharts classes, the Highcharts definition is from https://github.com/borisyankov/DefinitelyTyped/blob/master/highcharts/highcharts.d.ts
We all know HighchartsOptions has a property title.
If I define the object in this way, I have intellisense
But if I define object this way
I don't have the intellisense.
Any specific reason why Visual Studio behaves differently?
It's just a bug. See this issue on CodePlex to track when it gets fixed.

ReSharper: 'Name' attribute is not allowed here; use 'x:Name' instead in XAML

ReSharper's complaining about some of my XAML with the following error:
'Name' attribute is not allowed here
because type 'FlashingTextBlock' is
implemented in the same project. Use
'x:Name' instead
What's the problem here? Should I do what it says?
See an excellent explanations in this answer, and decide for your own ;)
In WPF, what are the differences between the x:Name and Name attributes?
Does FlashingTextBlock have a System.Windows.Markup.RuntimeNameProperty attribute?
According to "Windows Presentation Foundation Unleashed" by Adam Nathan:
... you can simply set its Name property to a string rather than use the x:Name syntax. You can use either mechanism, but you can't use both simultaneously.