Skip to content

wpdev

.NET / C#

Uncovering a bug in Attribute.GetHashCode

2017-03-26
By: Kevin Gosse
On: March 26, 2017
Tagged: .NET, C#

It started from a question on StackOverflow. The following code will return inconsistent value for the hashcode of the attribute: View the code on Gist. This will print the output: 1234567 0 0 We can see that the hashcode value changes between the first and second invocation. Even more interesting, commenting line 3 seems to fix the behavior and GetHashCode will always return 1234567. To understand what’s going on, we first need to look at the source code of the Attribute.GetHashCode method: View the code on Gist. In a nutshell, what it does is: Enumerate the fields of your attribute Find the first field thatRead More →

[UWP] NavigationService with back button handler priority

2016-02-21
By: Kevin Gosse
On: February 21, 2016
Tagged: .NET, C#, universal apps, WinRT, wpdev

There’s an issue I’ve encountered in every single of my UWP applications, so it’s very likely you know about it. In Universal Apps, you can subscribe to the SystemNavigationManager.GetForCurrentView().BackRequested event. It’s usually done firsthand to mimic Windows Phone’s behavior where pressing the back button loads the previous page in the back stack. So far, so good. But then comes the moment when you need to implement a back button behavior that is specific to a page. For instance, you have a popup and you want to dismiss it when the user presses the back button. So you subscribe once more to the SystemNavigationManager.GetForCurrentView().BackRequested event, implementRead More →

[UWP] Bandwidth adaptive image control

2016-01-13
By: Kevin Gosse
On: January 13, 2016
Tagged: .NET, C#, universal apps, WinRT, wpdev

There’s a dilemma you probably faced if you’ve written a mobile application displaying a large number of pictures. You could display gorgeous hi-resolution pictures, but if you do so, you’ll provide a poor experience to users who use your app on the go. Particularly, users with a poor mobile connection who will have to wait minutes before the pictures are displayed. You may also discontent users with limited data plans, who don’t want to eat gigabytes of data just to display your pictures. On the other hand, if you settle for low-resolution pictures, you’ll provide a sub-optimal experience you are at home, with an unlimited andRead More →

[uwp] Animation orchestration using Caliburn.Micro coroutines

2015-10-25
By: Kevin Gosse
On: October 25, 2015
Tagged: .NET, C#, Caliburn.Micro, universal apps, wpdev, xaml

MVVM is a commonly used design pattern for XAML-based applications (WPF, Silverlight, and now WinRT). I won’t go into a full description of the pattern, but I’d like to spend some time on a design issue I’ve encountered ever since I’ve started Silverlight/WinRT development. The issue Everybody will tell you: nowadays, for a good UX, animations are a must-have. XAML applications have a very powerful animation system based on storyboards, but it doesn’t fit well with MVVM. How so? One of the recommendation when using the MVVM pattern is to make a clear separation between the viewmodel and the view. The viewmodel should have noRead More →

Should I await the last call in a method

2015-09-12
By: Kevin Gosse
On: September 12, 2015
Tagged: .NET, C#, WinRT, wpdev

I came to write a code looking like this: Then I stepped back a bit and thought: OnNavigatedTo is an event, and its return type can’t be changed from void. Therefore, is there a point in awaiting the last asynchronous call of the method, as this will provide no information at all to the caller? Would it result in a useless call to the dispatcher, just to execute an empty callback? Actually, is the compiler smart enough to detect this case and remove the seemingly useless await? Understanding what’s going on How to figure out whether the last await call has any impact? Let’s say I add some code atRead More →

Debugging Visual Studio from Visual Studio

2015-09-05
By: Kevin Gosse
On: September 5, 2015
Tagged: .NET, Visual Studio, Windows 10, wpdev

When used to install various extensions and beta SDKs on your development machine, it often occurs that Visual Studio starts acting erratically, even to the point of stopping working. Sometimes, the workaround can be easily found by browsing through specialized websites, sometimes it can be much harder because you’re lacking information on the precise issue. That’s when trying to debug your IDE can help putting you in the right direction. I encountered such situation today, so I thought it would be interesting to share the few steps I had to go through. The symptoms It all started when trying to create my first Windows 10 project onRead More →

Label placement issue in Telerik RadCartesianChart

2015-08-30
By: Kevin Gosse
On: August 30, 2015
Tagged: .NET, C#, Silverlight, Telerik, wpdev

This is a strange corner-case in the way Telerik’s RadCartesianChart control handles the placement of labels. There is very little chance that you ever meet this bug, but if you do it can be quite unsettling, and that’s why I chose to cover it in this post. The setup First, what is this bug about? Let’s start by displaying a simple chart. The only twist here is that I use a converter to display the labels, because I want the user to be able to change the format dynamically: Nothing fancy in the converter: it parses the input if it’s numeric, then calls string.Format withRead More →

Dispatcher.Yield – When and how to use it on WinRT

2015-05-15
By: Kevin Gosse
On: May 15, 2015
Tagged: .NET, C#, WinRT, wpdev

That’s an issue happening from time to time. You need to do some lengthy computation on the UI thread (for instance, a page navigation), and you want to display a progress indicator to ease up the user waiting. It’s possible on WinRT thanks to the compositor thread: a dedicated thread for animations that don’t impact the page layout, making them run smoothly even when the UI thread is busy. Some built-in controls automatically use the compositor thread, such as the ProgressRing. So, what the issue could be? Letting the UI refresh Let’s say that when the user taps on a button, we want to displayRead More →

Inspecting unhandled exceptions – You’ve got only one chance

2015-04-12
By: Kevin Gosse
On: April 12, 2015
Tagged: C#, WinRT

That’s a surprising behavior, brought to my attention by this question of Anthony Wieser on MSDN forums. Basically, he noticed that in the global exception handler, he could read the stacktrace of the exception only once. On the subsequent tries, the value would be null. The debugging part We’ll start by making a simple program to reproduce the issue. When the user click on a button, we throw a custom exception: In the App.xaml.cs file, we subscribe to the unhandled exception handler, and print twice the stacktrace of the exception:  Sure enough, the stacktrace is printed only once. The second time, the property is null. What’sRead More →

Ken Burns effect with WinRT

2015-03-28
By: Kevin Gosse
On: March 28, 2015
Tagged: C#, WinRT, wpdev

In a mobile application, we often face the challenge of fitting a large picture in a limited, fixed-size space. One of the common solutions is to generate a thumbnail, but depending on the ratio of the picture the result will not necessarily meet the quality standards. In my case, I decided to try an alternative approach and mimic the built-in effect when pinning a picture as a secondary tile on Windows Phone, where the picture slowly scrolls from top to bottom (Ken Burns effect). There is no control on Windows Phone to produce this kind of effect, so I had to put together my own. FirstRead More →

Posts navigation

1 2 3 Next

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.

 

Loading Comments...