9. May 2012 06:12
I am working on making some information in my WinRT application available to the share charm in HTML format. The easiest way to insert data into HTML content is to use razor, which is the basis of one of the view engines in ASP.NET MVC. I’ll have a more detailed post soon on how to use razor with WinRT.
But in the meantime, I just wanted to quickly blog about using await within a razor file. In WinRT, much of the API uses asynchronous functions, so if you want to call back into your application to get something like an image, you may need to await the result.
Unfortunately, if you have code like this:
<img src="@await AddImage(imageFile)"/>
Then it won't compile. The solution is to use () around the expression, e.g:
<img src="@(await AddImage(imageFile))"/>
and then it works!
Hopefully this will help someone who encounters the same problem.
1. May 2012 14:55
In some of the default controls in WinRT XAML, when you press an item, such as a a GridViewItem it depresses down to indicate that has been tapped (pressed in pre-WinRT lingo!). However, if you use an ItemControl, this does not happen.
The desired behaviour can be seen by going to the apps list on the start screen and tapping an icon (is actually easier to test with a mouse) and what you will notice is that as you move out of the button it goes back to normal size, which is consistent with the way the buttons have always worked on Windows.
Someone recently asked about replicating this behaviour in the WinRT forum:
Unfortunately there is no default way to do this the moment, so I have built an extension that does this.
There is a bit of complexity in trying to ensure that the item returns to normal as you move out of or back into its rectangle. There doesn't seem to be an easily accessible WinRT function to confirm if your pointer is within the bounds. Hopefully I've just missed something and someone can correct me.
Anyway, to use it, register the namespace:
and add Controls:TapBehaviourExtension.TapBehavour="On" to your control. e.g:
<Image Controls:TapBehaviourExtension.TapBehavour="On" Source="Assets/Logo.png" Stretch="None"/>
Example project is here: