Visually Located


A simpler FilePicker for Windows Phone and Windows apps

If you’ve built a Windows Phone app that uses the FileOpenPicker you know that it can be a pain while the Windows variation is pretty simple to use. In Windows you use the PickSingleFileAsync method and continue code as you think you would. StorageFile storageFile = await openPicker.PickSingleFileAsync();// Do something with the file However in Windows Phone this becomes a little more complex. It’s especially complex when you look at the sample on MSDN. First you call the PickSingleFileAndContinue method, then in App.xaml.cs wait for the app to be activated, then somehow get back to where you were before. It’s a mess. I wanted to make this easier in a recent app I was working on and I wanted it to work the same for Windows and Windows Phone. To get started you’ll need to know that the CoreApplicationView can give us access to when the app is activated. With this, we can bypass all the weirdness of using the App class. CoreApplication.GetCurrentView().Activated += OnViewActivate... [More]

Creating a WrapPanel for your Windows Runtime apps

Recently I saw a friend, Glenn Versweyveld, write a blog about showing a “tags” (eg blog tags) within an app. The blog documents how to create a horizontal list of tags that are not formed into columns and rows. The list would let the items flow naturally. He used something I never would have thought of to accomplish this. He used a RichTextBlock. This was a rather cool idea that again, I would have never thought of. When I saw the blog I quickly asked why he did not just use a GridView or a WrapGrid/ItemsWrapGrid. His simple reply was that it did not accomplish what he wanted due to the row/column layout.. If you are on “Big Windows” the GridView lays items out into columns and rows, by filling up columns from left to right. If you are on Windows Phone the Grid View also lays items in rows and columns, but it fills up rows first instead of columns. The right picture shows Big Windows and the left shows phone. Ok, so GridView is out, how about a ListView and change the ItemsPan... [More]

Why does my ListView scroll to the top when navigating backwards?

I’ve seen a few people asking this question. They have a page which contains a ListView and when an item is selected it navigates to another page. When they navigate backwards the ListView is back up to the top again. This behavior is due to the NavigationCacheMode of the page. By default the page will not cache rendered content when navigating “forward”. So when you navigate back to the page it re-renders the content. When displaying content like a ListView this will cause it to show the top content. As with most things, there are a few solutions to this problem. The most common solution is to set the NaivationCacheMode to Enabled or Required. public ListPage(){ this.InitializeComponent();  this.NavigationCacheMode = NavigationCacheMode.Required;} These options do the following: Member Value Description Disabled 0 The page is never cached and a new instance of the page is created on each visit. Required 1 The page is cached and the cached insta... [More]

Alternatives to OpacityMask

In Windows Phone Silverlight apps you had the ability to take a png image and change the color of the image with an OpacityMask. This is a really handy tool to have when you want to show different state to a user or use one image and have it work with different backgrounds. Where is an example: <StackPanel Orientation="Horizontal"> <Image Source="Assets/" Width="72" Height="72"></Image> <Rectangle Fill="Red" Width="72" Height="72" > <Rectangle.OpacityMask> <ImageBrush ImageSource="Assets/" Stretch="Fill"/> </Rectangle.OpacityMask> </Rectangle> <Border Background="{StaticResource PhoneForegroundBrush}" Width="72" Height="72" > <Rectangle Fill="{StaticResource PhoneBackgroundBrush}" > <Rectangle.OpacityMask> <Image... [More]