Skip to content
wpdev

.NET / C#

Kevin Gosse (Page 3)

Software developer, .NET addict, Windows Phone enthusiast.

Twitter: @kookiz

Programmatically change the lock screen picture

2012-10-30
By: Kevin Gosse
On: October 30, 2012
Tagged: .NET, C#, Silverlight, Windows Phone 8, wpdev

Windows Phone 8 introduces a new API to allow apps to change the background picture displayed on the lock screen. The displayed picture can be picked from the application’s resources or from the isolated storage. To use this feature, you need first to declare it in the application’s manifest. Just add the following extension in the “Extensions” node: If you don’t already have an “Extensions” node in the manifest, you’ll have to add it at the same level as the “Capabilities” and “Tasks” nodes: Once the manifest is updated, there’s one remaining step before being able to change the wallpaper: the application must first askRead More →

Dynamically toggle PanoramaItem visibility

2012-07-01
By: Kevin Gosse
On: July 1, 2012
Tagged: .NET, C#, Silverlight, Windows Phone 7, wpdev

A strange issue with the Panorama control, that has been brought to my attention by @lancewmccarthy, and which has also been encountered by some people on StackOverflow. The original scenario was a bit too complex for a blog post, but we can reproduce it in a much simpler way. Create a new page, and add a panorama control called ‘Panorama’. Then add two PanoramaItem, and put a button in the first one: In the click event handler of the button, we toggle the visibility of the second item of the panorama: Start the application, try tapping on the button, and the visibility of the PanoramaItemRead More →

IsolatedStorageException when opening a file played by a MediaElement

2012-05-06
By: Kevin Gosse
On: May 6, 2012
Tagged: .NET, C#, Silverlight, Windows Phone 7, wpdev

Today we’ll dig a little into Windows Phone’s base class library, thanks to a question I found on stack overflow. The problem occurs with this simple code, used to load a music file from the isolated storage, and play it with a MediaElement: When executed for the first time, this code works fine. When executed a second time with the same file, it throws an IsolatedStorageException: “Operation not permitted on IsolatedStorageFileStream”. There isn’t many situations where opening a file from the isolated storage will throw an exception. The main two reasons are: an invalid filename, or a file sharing issue. Since the error only occursRead More →

Dynamically change startup page

2012-02-12
By: Kevin Gosse
On: February 12, 2012
Tagged: .NET, C#, Silverlight, wpdev

Let’s say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the ‘NavigationPage’ attribute in the manifest file. But the manifest cannot be modified once the application has been published. How to define it at runtime? For this, we’ll use a class very useful in ‘classical’ Silverlight, but widely forgotten on Windows Phone: UriMapper. In this example, we create an application with three pages (Page1, Page2, and Page3), and we want the startup page to be picked randomly among those three pages. First, change the manifest to use an inexistentRead More →

Inject a file in a xap using post-build event

2012-01-12
By: Kevin Gosse
On: January 12, 2012
Tagged: .NET, C#, Silverlight, wpdev, XNA

Let’s say that your application is dynamically loading resources, and you have to constantly add/remove new resources during the development. In this scenario, it could be a huge-time saver to just tell Visual Studio to take the contents of a folder and inject it into your application. I don’t think there’s an out-of-the-box way to do that, but you can inject the files yourself using a post-build event. How? The output of every WP7 project is a .xap file, which is just a zip file with a different extension. So you can edit it using whichever zip extractor you like. In our case, let’s useRead More →

Cryptic error message in XAML

2012-01-09
By: Kevin Gosse
On: January 9, 2012
Tagged: .NET, C#, Silverlight, wpdev

Unexpected NONE in parse rule ElementBody ::= ATTRIBUTE* ( PropertyElement | Content )* . ENDTAG.. Best. Error message. Ever. Thanks Silverlight. So, what’s going on? For the sake of all the devs who’ll come to this page using Google, let’s describe one of the causes of the error message. Is that it? Yes, pretty much. I don’t know if it’s the only possible cause, but it seems that this error message is triggered when an empty element is used in the XAML for a collection. In this case it’s the MenuItems of an ApplicationBar, but you can also have the problem with an empty rowRead More →

How to press the mouse on a control, and detect MouseLeftButtonUp on another

2012-01-08
By: Kevin Gosse
On: January 8, 2012
Tagged: .NET, C#, Silverlight, Windows Phone 7, wpdev

Another issue I found on StackOverflow, which is way more tricky that it seems. Let’s say we have a Silverlight WP7 application, and we want to add a drag&drop scenario. The user first taps an element, drags his finger to another, and raises his finger on another element. Easy enough! Just handle the MouseLeftButtonDown on each element, store which element triggered the event in a property, handle the MouseLeftButtonUp on each element, and then we have the originator and the destination! … right? Well, so I would have thought. Unfortunately, the MouseLeftButtonUp event will only be triggered if the ‘mouse’ left button (or your finger,Read More →

ApplicationBar flickering when the phone theme is white

2012-01-05
By: Kevin Gosse
On: January 5, 2012
Tagged: .NET, Silverlight, Windows Phone 7, wpdev

It’s an interesting issue I found on StackOverflow. Interesting because I often forget to test my applications using the Windows Phone’s white theme, so this kind of problem usually goes unnoticed until a user reports it. Create a simple WP7 application with a black background and an ApplicationBar. Add a button to toggle the bar’s visibility. The XAML should look like: And the ButtonClick method: Now launch the WP7 emulator, go in the settings, and set the phone theme to ‘light’. Then start the application, and try pressing the button: the application bar disappears as expected, but you may notice a quick white flickering. TheRead More →

Posts navigation

Previous 1 2 3

Recent Posts

  • Uncovering a bug in Attribute.GetHashCode
  • [UWP] NavigationService with back button handler priority
  • [UWP] Bandwidth adaptive image control
  • [uwp] Animation orchestration using Caliburn.Micro coroutines
  • Should I await the last call in a method

Archives

  • March 2017 (1)
  • February 2016 (1)
  • January 2016 (1)
  • October 2015 (1)
  • September 2015 (2)
  • August 2015 (1)
  • May 2015 (1)
  • April 2015 (1)
  • March 2015 (3)
  • October 2014 (1)
  • September 2014 (1)
  • November 2013 (1)
  • August 2013 (1)
  • May 2013 (1)
  • February 2013 (1)
  • December 2012 (1)
  • October 2012 (2)
  • July 2012 (1)
  • May 2012 (1)
  • February 2012 (1)
  • January 2012 (4)

Follow me on Twitter

My Tweets

Designed using Dispatch. Powered by WordPress.