drupal hit counter
Jerry Huang | apps and developing apps

Jerry Huang apps and developing apps

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
1
<textbox text="{Binding TextViewModelProperty}" updatesourcetrigger="PropertyChanged"> </textbox>

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

Code
1
2
3
4
5
6
object focusObj = FocusManager.GetFocusedElement();if (focusObj != null && focusObj is TextBox){var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);binding.UpdateSource();}

 

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
1
2
3
4
5
6
7
8
9
private void EnableControls(bool enabled){foreach (Microsoft.Phone.Shell.ApplicationBarIconButton btn in ApplicationBar.Buttons){btn.IsEnabled = enabled;}pvMain.IsEnabled = enabled;//the Pivot control}

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
1
<toolkit:PerformanceProgressBar x:Name="progressBar" VerticalAlignment="Top" IsIndeterminate="{Binding InProgress}" />

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

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
void vmNewTrans_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e){switch (e.PropertyName){case "InProgress":if (!vmNewTrans.InProgress){EnableControls(true);}break;}}

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

A major update of IP CAM Controller

8. February 2012 15:39 by Jerry in IP CAM, Windows Phone

I'm glad to annance that the v2.0 has been released to marketplace:)

V2.0 Relase Note
* App upgrades to Mango
* digital zooming
* pin camera to start and live tile update
* support new cameras: TP-Link, COMPRO, Level One, WansView,LogiLink
* new language: Swedish
* gesture support for pan and tilt scan
* Alarm and IR toggle for foscam, light toggle for axis

the new version is now based on the Mango WP7, that's why you will have those cool features like pin to start and live tile.

Are you ready to Mango? Let me know please...

11. January 2012 12:34 by Jerry in IP CAM

Recently I received a couple of great ideas from users (thanks, really!):

  • Live Tile support
    haven't made up the details, but one thing for sure is that the snapshot could be pin as icon or background
  • Pin the camera you created on IP CAM Controller to start screen
    this is really cool! Extremely fast to access to your camera, it's really one tap does the job. Moreover, you could use the camera snapshot as the back tile backgroup. (In Mango, each Tile has front one and back one, they are dynamically switched by the phone automatically)

However, as some of you may or maynot know, the current app is developed on earlier SDK (what we called 7.0 version) so that it's compatible with Mango and non-Mango (such as NoDo) devices. The above two features cannot be supported until the project is upgraded to SDK 7.1 (Mango SDK).

Once the project has been upgraded, the app is still available for non-Mango users, but they will not receive any update nofitication from marketplace, in other word, their IP CAM Controller will stick with existing version (v1.13) and not able to upgrade to any newer version until their phones are being upgraded.

I don't know how many people are still using earier version of Windows Phone, so I made a poll here, to collect your opinions and what phone you are using.

Please click here for the vote

 

The number one IP CAM app in "Music & Video" category on WP7 Marketplace

6. January 2012 18:21 by Jerry in

Finally, IP CAM Conotroller becomes the no. 1 IP Camera software in the Music & Video category, or ranking at top 18 in the category (US market) today. In the meanwhile, v1.13 has just been released.

I want to say thank you to all users (most likely they are parents like mecheeky). I'm so much appreciated for all your support in the past few months. As a result, I removed the time limitation on free trial from v1.13 version. Instead of having 3 minute limit on viewing for free trial users, there will be an ad bar showing up. The ad will be completely removed plus capacity of accessing multi view afte purchase. I hope this is acceptable for you.

The v1.13 starts to support multiple languages: Simplified and Traditional Chinese, German and Spanish (beta). Swedish will be coming in the next release, and maybe French:) If your language hasn't been listed, and you are happy to become an volunteer, please do contact me!

Voluntary translators wanted!

19. December 2011 17:52 by Jerry in IP CAM

I'm currently working on the localization of my app (IP CAM Controller), the next release of the app would at least support English and both Simplified and Traditional Chinese.

In fact, I wish to support as many languages as possible. So I would like to invite any one of you could help me out. If you are interested to be a volunteer, please click the "Contact" link at the top, and leave me a message with details such as what language you could do. I will reply you as soon as possible, thanks!

Lumia 800 pre-order

27. November 2011 01:37 by Jerry in Windows Phone

Although the Nokia officially annanced that the pre-order starts from Dec 2, I have just verified by myself that Nokia Lumia 800 pre-order could be made right now at Nokia's local store at HK. You need to pay HK$300 deposit for each phone you order. The deposit is un-refundable if you decide to cancel the order while it will count into the total amount when you pick up the phone and pay the rest.
 
According to the staff, the free earphone offer is available per phone if you place the order now. However, it won't be shipped with the phone at Dec 12, it will be provided later instead.
 
In case you are wondering, I ordered 3 lumia 800 myself at the Nokia store which next to Time Square at Causeway Bay.
 

The first Windows Phone 7 Nokia Lumia 800 released to HK

18. November 2011 22:27 by Jerry in Windows Phone
  • Price at HK$4,398
  • online pre-order starts from Dec 2
  • deliver at Dec 12
  • free Nokia WH-920 Purity earphone offer to the first 2000 orders
  • 3 colors available: Blue, Pink and Black
  • built-in local Apps include WhatsApp (well, this is not local), OpenRice, MyTV, TownGas, AAStock, HK Weather (mango update)
  • Internet Sharing will not be available initially, but will be avaialbe through update or download

 

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

IP CAM Controller now has free trial

27. October 2011 14:35 by Jerry in IP CAM

From v1.11 version, the IP CAM Controller will support free trial, and what's more? Price drops to $2.99 for saleyes

You can actually try if the app works for your camera without paying in advance.

As always, in case it doesn't work or has any question, click the "Contact" link above to leave me a message.

For those WP7er who is expecting Whatsapp

21. September 2011 12:13 by Jerry in Windows Phone

Whatsapp just released its beta, it's private beta however, so you are not able to download from market. However, you could directly download from here if your phone is dev unlocked:)

WhatsApp.rar (873.45 kb)

It's not quite stable however. It directly access to all your phone contacts and add those who already used whatsapp to a "favs" list. Then you could send message from people in that list, but it seems couldn't locate my overseas friends whose phone number have a country code prefix. You can also see all your contacts in an "all" list, but sometimes it crashs when I scroll down the list.