drupal hit counter
Jerry Huang | Windows Phone Development

Jerry Huang apps and developing apps

Next stop: win 10

I wrote a blog post (here) last year whether I should or should not upgrade my development from WP8 to WP8.1, and my conclusion was "no go". Basically it's not worth it. I believe that I made the right decision back then, because otherwise I will fall into similar situation again, Win/WP8.1 -> Win10.

 

I have been keep track of MSFT's app development for a few years now, and honestly I'm tired and a bit sick about that. Because every time MSFT announce something new, something they are really excited about, developers need to drop something they had been familiar with and rewrite the codes. Even worse, the "excitement" is short, the "new thing" becomes worthless in just maybe 1 or 2 years (such as WP7, Silverlight). Maybe that's the reason WP's market didn't go any further in the past few years - At first, MSFT pissed off customers (WP users) by announcing WP7 cannot upgrade to WP8, and then MSFT pissed off developers by keep introducing new stuff without backward compatibility. Myself for example, I brought 3 lumia 800 phones (the price of 800 is almost the same as iPhone back then) at the beginning, when lumia 930 launch, I hesitated and eventually I went with lumia 720 and half year ago I switched to iPhone. I wouldn't call myself a loyal user of MSFT but I start using MSFT's phone since Windows Mobile 5. I don't know too much about marketing, but this is really sucks!

 

Being said that, the good thing is that MSFT seems to aware of the problems they are having. I attended the Build Tour in my city yesterday. They start to demonstrate MSFT technologies on competitors' products, such as MacBook and iPhone; and I'm sure you heard of MSFT start to attract Android and iOS developers by supporting them in the new VS2015 (probably because they are losing their own developers??LOL); MSFT is having an open-mind more than ever. This is good but this is far from enough and I believe they know it.

 

Win10, after a few years' struggling, this piece of ....... thing looks decent to me, from a developer's angle of course (I heard some noise about the UI changes BTW). But on the other hand, as usual, every upgrade is painful, especially true for WP developers. I would rather not going too much details here, you may have a taste by reading this post: http://blogs.msdn.com/b/lucian/archive/2015/06/09/win10-apps-in-net-porting-from-8-1-universal-to-win10.aspx

In short, it's not that bad by comparing transitions in the past, because most codes and XAML should be still useful while for 3rd part controls just give it some time, they will be supporting win10 sooner or later. At the very least, the underlaying frameworks are not being changed; they are not turning the framework up side down this time like what they did in Silverlight to WinRT. But I feel lucky and happy that I didn't go for WP8.1 last year because that is simply not the final stop. While for this time, I probably will go for win10:)

 

PS. yesterday's Build Tour, free entrance, free foods, basically free of everything and you could get a nice Build t-shirt at the end:))))))

WP8.1: 想说爱你不容易

8. August 2014 12:42 by Jerry in Windows Phone Development

MSFT is about to rolling out the gorgeous WP81 update - the biggest and the most important upgrade in the history. And that is a nightmare for most app developers like meCry

First of all, for those who are having trouble with the title of this post, please kindly click here for translation. I just couldn't find a better title than that and it's time for you guys to learn some Chinese, LOLCool

When I upgraded from WP7 to WP7.8, I don't have too much trouble and of course less excitement - it was nothing but adding a socket (to some extend:). When it came to WP7 to WP8, I was excited because C++ is available and the app finally support audio. I have done a lot of coding at that upgrade but mostly about new functionalities - I don't have to rewrite everything.

Now, things are getting more complicated and it looks like there isn't much benefit I could have (neither the app user). There are 2 options to upgrade the development from WP8 to WP8.1, let's start with a nice comparison: http://msdn.microsoft.com/library/windows/apps/dn655121(v=vs.105).aspx

There are actually 3 options in above article but option 1 (not upgrading) is out of the table as we want to move on and believe me that's the last option MSFT ever want (they put huge money on the new WP81 but telling you to hold off, no way!).  For the other 2 options let's read a discussion I found here: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/bf855b7f-d7ca-4b73-964f-22ac77f7d4c4/benefits-of-windows-runtime-over-silverlight-in-wp81?forum=wpdevelop

To simply put, there are 2 different WP8.1 in terms of development framework, one is Silverlight 8.1 (SL8.1) while another is Windows Runtime (WinRT, aka Universal app). The latter one is the same framework when you develop a Win8.1 store app for Windows tablets and/or W8.1 desktop (Metro). Although MSFT claims that they are equivalent about everything, the truth is that WinRT (universal app) is being seriously promoted right now while SL8.1 in my opinion is something intermediate during the transition (remember WP7.8 before WP8, sound familiar?).

If I predict above correctly, RT is the future for app development (phone and tablet) on Microsoft's platform, therefore in long term I would like my development to be on that. However, it really means to rewrite the whole app again - not everything, but still a lot including the UI. And it becomes more trouble if your projects have reference to 3rd party libraries (which is very common for even a small project) - they need to upgrade to support that as well.

When I say "including the UI", I mean:

  1. This only apply to WP8 -> WinRT upgrade path
  2. XAML is not reusable, because the UI framework are different between WP8 and WinRT, you may consider things are being rewritten/re-design in WinRT.
  3. There are a lot of UI controls available in wp8 have gone or being replaced. such as LongListSelector (replaced by GridView or ListView or maybe something else), <controls:Pivot> becomes just <Pivot>, etc
  4. If you are porting your WP8.1 app from a Win8.1 app, and if you use lib like WinRT XAML Toolkit, you need to find alternative or wait for future update from the component developer because currently doesn't support WP8.1 just yet
  5. If you are upgrading from a WP8 app, and if you use lib like Coding4Fun toolkit, similar to above, you have to find alternative or wait for update because current version doesn't support WP8.1
  6. Don't forget doing so much will not bring any improvement or new feature to your users, instead, it's very likely to cause some bugs as the changes are about everything: UI, API, etc

 

So what if we go with SL8.1 as MSDN suggests just some changes? It's much less painful (above item 5 is also applicable though) but keep in mind that WP8.1 is new, you might still have a lot of users on the old platform and so you need to maintain development on 2 platforms (if you care those users). As a result, you will have to clone a new set of projects (including the UI project) from your WP8 solution (you will need linked files); and re-target the new projects to WP8.1. After that, any change, especially on the UI, you are likely to code twice. This kind of maintenance will last for a while base on my experience, until WP8 is completely or almost fading out.

I haven't completely decided yet how to upgrade my development for my app, for now, I would rather just sit tight and watchCool

"Order By Ranking DESC" Became Order By Ranking ASC"?? Breaking news?

10. May 2013 21:32 by Jerry in Windows Phone, Windows Phone Development

If you are from US or your Live Id's country setting configured as US, you will notice that something is seriously wrong on the Windows Phone store (marketplace) about ranking: The display order of "Top" apps in all categories (except the "All" one) seem reversed on this morning. Please have a look at the photos I just took: 

 

 

This problem apply to the web market as well:

http://www.windowsphone.com/en-us/store/top-paid-apps/music-video/musicandvideo 

 

As you could see, most of the "top" apps do not have or have very few review and rating. I hope Microsoft could resolve this as soon as possible. Yesterday my IP CAM Controller was ranking at the top 11 position in the "Music + Video" category.

Translation between WP and Win8 Metro series: loading byte array into BitmapImage

1. November 2012 14:07 by Jerry in C#, Win8 Development, Windows Phone Development

WP

[code language=C#]
byte[] frameBuffer;
BitmapImage.SetSource(new MemoryStream(frameBuffer, 0, frameBuffer.Length));
[/code]

Win8

[code language=C#]
 var ms = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                        ms.AsStreamForWrite().Write(frameBuffer, 0, frameBuffer.Length);
                        ms.Seek(0);
                        BitmapImage.SetSource(ms);
[/code]

it looks to me that Win8 just making thing complicated:(

Translation between WP and Win8 Metro series: async anonymous method in Win8

1. November 2012 13:48 by Jerry in C#, Win8 Development, Windows Phone Development

As I mentioned previously, I'm trying to develop a Win8 Metro version of IP CAM Coontroller, so I'm basically translating the WP coding into Win8. I'm going to post a series of blog post to record (and so benefit those googler with same problem) some of the interesting issue and topic.

WP coding:

[code language=C#]
Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            //do something here
                        }
                        );
[/code]

WIN8

[code language=C#]
 Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                new Windows.UI.Core.DispatchedHandler(() =>
                {
                    //do something here
                }));
[/code]

This is not end of the story, by using the RunAsync like above, you will get a compiler warning from VS2012, and it's interesting that if you assign the returning result (of RunAsync) to a variable, the warning goes away. So the final version is like:

[code language=C#]
 var dummy = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                new Windows.UI.Core.DispatchedHandler(() =>
                {
                    //do something here
                }));
[/code]

A monthly view calendar in Windows Phone

17. June 2012 15:45 by Jerry in Windows Phone, Windows Phone Development

For some reason, I need a calendar control in a WP7 app, a special one, or a simple one. However, within the most exciting Metro world, it doesn't easy to get high sometimes - officially you don't have calendar control, you need to google it and, you don't have too many opotions after google. This is one of the biggest problem of WP7 development in my opinion. There is too few controls for developers to use.

Anyway, the control I need is a months view calendar that shows 12 months of the year and probably highlighted the current month. The year could be changed somehow. Eventually I found the regular calendar here:

http://adayofrequiem.blogspot.hk/2012/03/month-view-calendar-for-wp7.html

It said it's a "month-view-calendar" but it''s not really the month-view in this articlefrown, so based on the author's source code, I made my own MothView control. Take a look:

It doesn't look very excited, you may need to decorate a little to make it looks pretty. Here is the full source code:

monthview.rar (174.37 kb)

Force a data binding to update

16. June 2012 18:41 by Jerry in Windows Phone Development

The beauty of data binding in Silverlight or WP7 is that it completely separate the UI and data access logics. The ugliness of data binding however is that it doesn't work or work as expect sometimes. The problem is always in Two-Way binding for data input. Consider a very common and straightforward scenario:

A regular page that contains a few textboxes and listpickers for user to input something, and there are 2 buttons inside the application bar - done and cancel. Once user tap the "done" button, data save( or do some validation before that); tap the cancel button simply reset all data input controls. As a result, the best way to implement this is to use a two-way data binding that binding the textbox's Text property to your ViewModal class. Very easy, just a few lines of coding. Is that it? In most cases, yes. However.......

If a user is tapping the "done" button without leaving the textbox (i.e. without losing focus on the textbox), what will happen? The expected behavior is the text binding to viewmodal class and data get saved. You are just too innocent if you think sowink. The text will never get update to your viewmodal class before losing focus. The reason is that the default UpdateSourceTrigger (check MSDN for details) for a textbox (or maybe other controls) is the LostFocus event. With WPF, you may easily change this property like:

[code language=XML]<textbox text="{Binding TextViewModelProperty}" updatesourcetrigger="PropertyChanged"> </textbox>[/code]

In Siliverlight for WP7 however, the XAML doesn't support UpdateSourceTrigger, so you will have to do it manually in your save function:

[code language=C#]object focusObj = FocusManager.GetFocusedElement();
if (focusObj != null && focusObj is TextBox)
{
    var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);
    binding.UpdateSource();
}[/code]

 

Once the UpdateSource methid is called, text will be flush to your view-model class. This is the way I used to force a data binding to be inforced. Above coding is based on the post here (no 9 answer):

http://stackoverflow.com/questions/5569768/textbox-binding-twoway-doesnt-update-until-focus-lost-wp7

*credit goes to "StefanWick" and "rrhartjr" (for the WPF part)

 

Is this the end of the story? Is your input page perfect now?  Hoho you wish. The following issue is not really related to data binding but it's very common in every data-input-page with use of application bar button to save. The problem is that data will be save twice if you tap the "done" button quick enough. This bug is actully exists in the latest Facebook app. When you post a piece of comment on somebody's photo in (WP7 facebook app), once tap the "send" button, progress bar (the dot dot dot stuff) shows up at top of the screen, if you tap the "send" button again (believe me, you can), your comment will be posted twice.

I don't know how others resolve this issue, but here is what I did:

1) Write a private function in the xaml.cs
[code language=C#]
         private void EnableControls(bool enabled)
         {
             foreach (Microsoft.Phone.Shell.ApplicationBarIconButton btn in ApplicationBar.Buttons)
             {
                 btn.IsEnabled = enabled;
             }
             pvMain.IsEnabled = enabled;//the Pivot control
         }
 [/code]

2) call EnableControls(false); before the save data function

3) I assume you will bind a property like "InProgress" to the progress bar's IsIndeterminate property, like:

[code language=XML]<toolkit:PerformanceProgressBar x:Name="progressBar" VerticalAlignment="Top" IsIndeterminate="{Binding InProgress}" />[/code]

so the trick here is to call EnableControls(true) when the InProgress becomes false which means the data is saved.
 

[code language=C#]
        void vmNewTrans_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "InProgress":
                    if (!vmNewTrans.InProgress)
                    {
                        EnableControls(true);
                    }
                    break;
            }
        }
[/code]

That's it! No matter how quick you try to save twice, you will never get duplicated data:)

WP7 push notification summary

7. November 2011 17:04 by Jerry in Windows Phone Development

First of all, here is a high level briefing how push notification works and what have been involved.

Parties:
1) your phone application: register push service; receiving notifications
2) your server: sending messages
3) the so-called "Windows Azure": microsoft server (MPNS, Microsoft push notification services), assignning token to your application; forwarding alerts (sent from your server) to your application

Now let's see how it actually works.

step 1) Your application will first register with Azure, and will be assigned back an URI (token) if the registration is successful. P.S: the token is unique per application per device, so that one token would be able to tell the Azure which app on which phone.

step 2) Your application must tell your own server that what URI has been returned (by calling a web service would be classic). It's your job to maintain the subscriber list on your server side. Once a condition is met for sending out an alert to a device, your server application will then use the URI (that previous notified by your app) to send a message (which its format is pre-define by Microsoft) to Azure service.

step 3) Eventually the message will then be transfered to target device via Azure service.

For the details of implementing these steps, I'm pretty sure you would be able to find a bunch of samples and resources via Mr. Google. So, go for itwink

Next, there are 3 types of notification currently supported by WP7.0 and 7.1:

1) Raw. Custom format, maximum 1KB for the message. The message will be discarded ("Suppressed" status) by Azure if your app is not currently running on the phone.

2) Tile. User must "pin to start" your app, otherwise, the message will be discarded ("Suppressed" status) by Azure. The image URI could be pointing to remote (internet) or local (within the phone), as long as it's valid. For remote image, the size must be less than 80KB and the download time has to be less than 1 minute.

3) Toast. If the phone is switch off, the message will have the connection status "TempDisconnected"

What else you may need to know? Here you go...

1) MSDN: http://msdn.microsoft.com/en-us/library/ff402558(v=vs.92).aspx

2) 500 messages per application per device per 24 hours if your server doesn't use SSL to communicate with Azure. By using SSL, you will need to upload your cert via your developer account, and then this limitation is not applicable on your apps. details: http://msdn.microsoft.com/en-us/library/ff941099(v=VS.92).aspx. Last but not least for this issue, a very stupid action is required that you must upload the cert every 4 months if the post here is ture (which most likely is): http://forums.create.msdn.com/forums/t/85207.aspx

HD2 Mango: error during registering with your developer account

9. July 2011 19:45 by Jerry in Windows Phone Development

If you are a WP7 marketplace paid developer like me who is not working on a "real" WP7 handset, instead, using HD2. You will find VS2010 cannot debug with your phone after freshing the custom ROM for HD2. The VS2010 compaint that:

The application could not be launched for debugging. Ensure that the target device screen is unlocked and that the application is installed

And then you probably will try to register your phone since you had paid for the 3 developer unlock quota from App Hub. However, the registration program will also throw an error "Error communicating with the developer portal" with error code 0x64. You will know 0x64 is because the phone cannot connect the App Hub registration services after google.

 So what now? Give it up? After some thinking, I suspect the problem is due to the ROM embeded with the "prevent relock" patch which causing the phone cannot connect the registration services. The so-called "prevent unlock" patch is actualy a Registry hack to remove the URL of developer portal which will causing the phone to be relock when connecting with Zune. If so, what I need to do is update the URL back.

[code language=XML]

<wap-provisioningdoc>
<!-- *** COMMENTO *** -->
   <characteristic type="Registry">
      <characteristic type="HKLM\Comm\Security\LVMod">
         <parm name="DeveloperUnlockState" value="0" datatype="integer" />
      </characteristic>
      <characteristic type="HKLM\Software\Microsoft\DeviceReg">
         <parm name="PortalUrlProd" value="https://developerservices.windowsphone.com/Services/WindowsPhoneRegistration.svc/01/2010" datatype="string" />
         <parm name="PortalUrlInt" value="https://developerservices.windowsphone-int.com/Services/WindowsPhoneRegistration.svc/01/2010" datatype="string" />
      </characteristic>
      <characteristic type="HKLM\Software\Microsoft\DeviceReg\Install">
         <parm name="MaxUnsignedApp" value="2147483647" datatype="integer" />
      </characteristic>
   </characteristic>
</wap-provisioningdoc>
[/code]

so I made a relock XAP base on above setup, run on my HD2, reboot (must reboot, otherwise won't take effect), register again, done!

The relock XAP could be downlod here (rename to .xap after download), deploy to your phone, tap "HTC-ProvXml-Deploy", click the green icon, your HD2 will be relock again.

 

ListPicker performance tuning

8. June 2011 22:53 by Jerry in UI, Windows Phone Development

The ListPicker control in Silverlight for Windows Phone Toolkit (Feb 2011 release) has become famous after its poor performance.wink My app IP CAM Controller for example, starts from v1.6, I used ListPicker to accommodate the full list of supported camera types and brands. The total item number is about 20 to 30, while it took 3 to 5 seconds to get response when openning the setup page. It's really a huge lag.

Thanks to Pedro Lamas who solved this problem by changing the source code in a few places. Details please refer to here:

http://www.pedrolamas.com/2011/06/02/listpicker-a-cafeina/

It's not in english, but translator is available on the right up side of the page. He also submitted a patch to the official Toolkit project on CodePlex here:

http://silverlight.codeplex.com/SourceControl/list/patches

patch ID 9632, providing a brief summary in english.

Good news for those lazy people (such as meblush), I attached the compiled binary and source file base on Pedro's blog, feel free to download from here.

Unzip the file and copy the two files (Microsoft.Phone.Controls.Toolkit.dll and Microsoft.Phone.Controls.Toolkit.pdb) to your Toolkit installation folder, e.g.

C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Toolkit\Feb11\Bin\