I’ve seen the rumbling a few times now about property setting in Silverlight.  The rumblings are along the lines of “why do I have to use SetValue for setting simple properties like the x/y positioning?”  To those points, I agree from a fundamental standpoint.  From a technical standpoint SetValue is there and serves a great purpose for providing a common way of setting properties on XAML elements regardless of the element.  As a developer, I like it actually.  I do, however, see the point about wanting to set simple properties and it just looks a little verbose.  Take for instance setting the x/y positioning of an Ellipse (in code):

   1: Ellipse circle = new Ellipse();
   2: circle.Width = 10;
   3: circle.Height = 10;
   4: circle.SetValue(NameProperty, "MyCircle");
   5: circle.SetValue(Canvas.TopProperty, 200);
   6: circle.SetValue(Canvas.LeftProperty, 200);

You’ll see the last three lines seem a little verbose when setting simple properties.  Most of the time you’ll run into this using your own custom controls or while providing controls to others.  Here’s a tip to simplify this process…abstract these simple ones away if you know they will be used frequently.

Developers familiar with Flash/Flex will note that for something like the above example, there are .x and .y values.  We can do the same with Silverlight by ensuring our controls follow a pattern we anticipate our developers will use.  Let’s say we have a control called MyCircle which contains only an Ellipse.  We know that our consumers of our control will be animating our circle control using various calculations and moving x/y coordinates frequently.  In our control we can do this (assuming our XAML has an Ellipse in a Canvas element):

   1: public double X
   2: {
   3:     get { return this.GetValue(Canvas.LeftProperty) as double; }
   4:     set { this.SetValue(Canvas.LeftProperty, value); }
   5: }
   6:  
   7: public double Y
   8: {
   9:     get { return this.GetValue(Canvas.TopProperty) as double; }
  10:     set { this.SetValue(Canvas.TopProperty, value); }
  11: }

Now when developers need to move this control around they can simplify things by writing code like this:

   1: MyCircle circle = new MyCircle();
   2: circle.X = 200;
   3: circle.Y = 200;

By doing this we’ve abstracted out the SetValue/GetValue functions (while still there if needed) for some simple properties.  I like this tip a lot and generally is helpful when you need quick/simple access to properties like this.  I learned this tip from Rick Barraza who incidentally does work in Flash, Flex, WPF and Silverlight.  He uses this technique when doing a lot of manipulation of objects that involve math, etc. – in the end the result is the same, but this tip might save you some precious keystrokes.

Well, it seems that in addition to problems with MobileMe, Apple is getting into some gray area with AppStore.  Applications are appearing, disappearing without explanation to the authors.  The one that got more attention was NetShare, an app that purports to enable tethering of your iPhone 3G.  However despite it being available (actually for me clicking on the link it wasn’t even available then) it seems to be performing one of Criss Angel’s greatest feats in appearing/disappearing at will (or at Steve Jobs’ request).

The latest app to fall to this scenario and be removed from the AppStore without explanation is BoxOffice.  The developer of BoxOffice posted a plea on MacForums:

Apple pulled the app yesterday without giving my any notification that they were doing it, or what their justification was for removing it.


I've tried to contact them about the issue, but it's been a complete dead end. If anyone has a useful contact number for apple, please let me know.


I'm in regular contact with all my data providers, and none of them have had an issue with my app. Indeed, the response was the exact opposite. They like my app and have even asked if i would do custom application work for them in the future. Furthermore, all the data i use is licensed by the owners as 'free for non commercial use'. i.e. precisely what BoxOffice is. Source: MacForums

Here’s my guesses (and only guesses):

1) NetShare pulled because of violation of AT&T terms.  I can’t cite them specifically but I’m pretty sure there is some fine print about tethering and normal use.  Heck AT&T sells a tethering option on some of their devices so I’m sure their crafty attorneys have legalese in their normal terms for 3G devices like iPhone about tethering. 

2) BoxOffice – pulled because it is Open Source licensed under the GPLv2.  BoxOffice has had it’s code up there on Google Code for a while.  Could this be a sign that Apple is now getting around to tightening their reigns on their terms and that OSS applications would not be allowed?  Or perhaps because he has a ‘Donate’ button in the app and Apple can’t get their chocolaty fingers on any donations (which probably violates the terms anyway-however other apps do the same thing).  I can’t wait to see what Cyrus hears back regarding BoxOffice and why it was removed.  And if he does receive that reason…will WordPress follow next?

What gives with updates?

The AppStore model was an exciting one.  I say was becuase I’m starting to see some faults.  This whole appearing/disappearing thing without communication to the authors is frustrating.  Even if they are in violation of whatever terms…a communication to the author is something that should occur.  “Hey you are violating terms XYZ, if you want to be listed in the AppStore you need to patch your software and re-submit.”  Is that so hard?

The other pain I’m seeing is updating.  While the AppStore seemed a great model, the update model sucks big time.  Authors have to go through the same process to submit an update it seems as they would a new app.  For real?  So 1.0 to 1.1 takes forever?  Is that a model that is acceptable to the security world?  What if someone found an exploit in Super Monkey Ball that it was actually taking your contacts and passing them around somewhere?  The v1.x patch has to go through a similar process of a new app?  Seems strange.

The other updating just seems hokey to me.  It really isn’t enabling a software+services model.  One case is the apps that provide reference.  For example, I downloaded the Spanish phrase app (handy by the way).  Let’s say the authors want to add more phrases.  They have to release a whole other app!  I have to download/install a whole other app.  Why can’t the author have their own update mechanism like other real software?!  Imagine if that every time your favorite app was updated you had to completely re-install it each time.  Ridiculous right?  Why should an iPhone app be any different.  Enabling this model of auto-updating should be added to their SDK to enable authors to quickly provide patches and incremental updates to their applications without the AppStore getting in the way.

Well, it is interesting to see how Apple is going through these pains in their new adventures.

I’ve just finished reading a book recommended to me.  You see, I don’t read much.  I tend to stick to technical reference documentation and if I do choose to read it is usually something involving challenging thought, social economics or conspiracy theories.  My favorite book is probably Freakonomics which challenged my way of thinking, provided some interesting social economic studies and really just was an interesting perspective on various things.  I highly recommend you get that book.

Predictably Irrational book cover My Silverlight compadre Jesse said that if I liked that book I should rush out and get Predictably Irrational.  I did.  This past weekend I had some downtime while camping (a whole other story I wish not to relive in the near term) with my family and chose to get into this book.

Wow.  What a great companion to Freakonomics!  Seriously if you’ve read Freakonomics it is a pretty high likelihood that you will like Predictably Irrational as well.  Dan Ariely survived a pretty bad accident and during his hospital healing process there were a few things that caused him to think about how humans act, assume and generate habits.  He’s a PhD from MIT (the book has various MIT vs. Stanford vs. Harvard jabs in it) and seems to surround himself with other interesting people.

The social experiments conducted during his research are pretty obvious and you can totally expect the results, but the analysis and different ways of thinking about them are intriguing.  I was particularly taken back by the study on honesty and how when the opportunity is given to cheat, unless it directly involves cash, it is almost a certainty that even the most honest people will.  However, make them write down the 10 commandments before they do the activity and not a single participant cheated.  The mere suggestion (note: not everyone even knew them or wrote them all down) of the 10 commandments was enough to get people to think twice even in situations where they would be guaranteed not to be caught.

Anyhow, a great read.  A fun read.  Get it now.

NDA.  Non-disclosure.  Hush documents.

Not many people like them.  In the technology world they are a necessary evil.  Personally I don’t think that way.  I think NDA’s are generally a good thing.  It’s enabling legalese to let two parties participate in information exchange when they don’t want the rest of the world to know about them.  NDA is a general term, of course, and the wording in any non-disclosure agreement is subject to the two parties involved.  Heck it could say “We’re going to show you everything and you agree only to not talk about feature X…everything else is fair game.”  Usually they don’t.

Enter the iPhone SDK.  The frustrating part for iPhone developers wanting to share their knowledge, innovate on the platform, etc.  It was assumed from a lot of developers that upon the release of iPhone 2.0 software that the NDA would be lifted.  Guess what – it isn’t (as of this writing).  What does that mean?  Well, among other things, people who have the SDK are under that NDA and shouldn’t be discussing it with anyone other than Apple.  Guess what…even if your best friend is under the same NDA, technically your agreement is only with Apple, not ‘anyone else under NDA.’

My local Cocoa/iPhone user group in my area recently shut off their email list and posted this message:

“IMPORTANT NOTE: AT THE PRESENT, IN ORDER TO RESPECT THE IPHONE DEVELOPER TERMS AND CONDITIONS, WE HAVE DEFERRED MESSAGE POSTING AND OUR FIRST MEETING UNTIL OPEN DISCUSSION ON IPHONE DEVELOPMENT IS ALLOWED BY THE NDA, AND BLESSED BY APPLE. OUR GOAL IS TO PROMOTE APPLE IPHONE TECHNOLOGY ACCORDING TO PROPER GUIDELINES AND NOT PRESENT EVEN AN APPEARANCE OF IMPROPRIETY. ALL GROUP MEMBERS WILL BE NOTIFIED AS SOON AS WE ARE FREE TO OPENLY COLLABORATE.” source: Phoenix iPhone Developer Group

As frustrating as it is for passionate folks, bravo to this group to at least ensuring their channel they’ve created isn’t a faucet of information that shouldn’t be shared just yet.  There are other groups that I’ve seen hosting iPhone developer discussions and I can’t imagine how they are doing that without talking about thing that violate the agreement they have in place. 

NOTE: If you downloaded the SDK, you agreed to the NDA – sorry if you didn’t read it, but you did.

An NDA is in place to provide valuable information to those who want to agree to it.  By not honoring that you’re stealing information essentially.  Beyond the legal stuff which I don’t pretend to understand in a deep manner, it just isn’t really ethical for you as an individual, business, developer, community, whatever.  I don’t care if it is with a darling company like Apple…no matter what if you agree you should be responsible. 

Another part of the SDK is the terms.  Besides not being able to be discussed, shown, shared, the terms of the iPhone SDK might prohibit any open source project.  Which brings into question the project from Wordpress.  This is an AppStore approved app that now has source available. (which is using the GPL license).  As Nathan Willis of Linux.com points out that two terms of the SDK and AppStore deployment violate explicitly the GPL (nondisclosure and code signing).  Wordpress putting the source out there violates not only the terms of the iPhone SDK but as well isn’t in line with the GPL they have selected.  How is nobody claiming shame on them?  Just because they are open source doesn’t mean they have the right to violate agreements.

Yes, I know Microsoft isn’t open source all the way by ANY means.  I don’t believe I’ve ever made that comment and certainly not here…this isn’t about a ‘well then you should to’ but rather about honoring known agreements and terms/conditions of use.

If people get lost in a frenzy of excitement and decide just to start violating things they agree to, where does that leave organizations wanting to plan and share information?  There isn’t a lot of trust left is there?  I honestly think that Apple will rectify this soon and perhaps it is just an oversight while they are dealing with the MobileMe troubles as of late, but regardless the terms are still there, the confidentiality agreements are still in place and if you agreed to them, you should honor them.  I know that is a bit of a “duh” moment…but seeing stuff like what Wordpress is doing and user groups sprouting information makes me sad that we as professionals have disregard for these types of things.

I had an idea for an iPhone app that I wanted to do to manage the life-sucking-battery-settings and others even wrote they’d pay money for that app.  When I had the idea I immediately contacted an Apple evangelist and began starting a discussion about this.  Turns out that the settings I’d need to get to aren’t available according to this evangelist in email.  I noticed the iPhone dev team has the headers needed, but even completing the app wouldn’t give me any distribution beyond myself because the mere coding against the properties would violate the terms and wouldn’t be approved in AppStore.  I suspect an app like this will surface (perhaps in the Jailbreak world) and if it does on AppStore, I’ll be pissed that I was misinformed and missed out on an opportunity!  Where was I?  Oh yeah, anyway I went to the source (Apple), inquired, and was told it wasn’t possible per the terms.  It sucks, but I’m going to honor those terms…because I agreed to.

And if you did, so should you.  Wordpress…shame on you.

Related articles:

If you are working with Silverlight and data you most likely are going to leverage data binding at some point and run into some needs to format the data in the XAML.  Luckily this can be done using value converters, which have been available for WPF since it’s inception as well.  Let’s explore what I’m talking about using a common formatting need: dates.

Consider this list box output binding:

   1: <ListBox x:Name="FeedList">
   2:     <ListBox.ItemTemplate>
   3:         <DataTemplate>
   4:             <StackPanel Orientation="Vertical">
   5:                 <TextBlock FontFamily="Arial" FontWeight="Bold" Foreground="Red" Text="{Binding Title.Text}" />
   6:                 <TextBlock FontFamily="Arial" Text="{Binding PublishDate}" />
   7:             </StackPanel>
   8:         </DataTemplate>
   9:     </ListBox.ItemTemplate>
  10: </ListBox>

Assume this XAML binds to SyndicationFeed.Items data coming from an RSS feed.  If we simply bind it the result would be this:

Maybe we don’t want our date to be formatted in such ‘system’ looking format and we want something like “July 16.”  Enter the IValueConverter class.  First we’ll add a class to our Silverlight application, let’s call it Formatter.  Once we add that class we need to implement the IValueConverter interface which gives us Convert and ConvertBack functions we have to implement:

   1: public class Formatter : IValueConverter
   2: {
   3:     #region IValueConverter Members
   4:  
   5:     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
   6:     {
   7:         throw new NotImplementedException();
   8:     }
   9:  
  10:     public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  11:     {
  12:         throw new NotImplementedException();
  13:     }
  14:  
  15:     #endregion
  16: }

You can see that the Convert function gets some good information that we can use to do the conversion.  The parameter value is the formatter passed into the argument.  For example in our desire to display “July 16” we want to use the date formatter shortcut of “M” for the parameter.  Let’s start the conversion.

   1: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
   2: {
   3:     if (parameter != null)
   4:     {
   5:         string formatterString = parameter.ToString();
   6:  
   7:         if (!string.IsNullOrEmpty(formatterString))
   8:         {
   9:             return string.Format(culture, formatterString, value);
  10:         }
  11:     }
  12:  
  13:     return value.ToString();
  14: }

What we are doing here is ensuring that a parameter is passed in and then using the String object to handle the formatting for us.  Great, now we have our Convert function (in this sample we are doing one-way binding so I’m going to leave ConvertBack alone for now).  Let’s compile our code and then move back to the XAML.  In XAML we now want to make our converter available for use.  The first step is to add the CLR namespace to our root XAML node:

   1: xmlns:converter="clr-namespace:TypeConverter_CS"

The next step is to add our converter class as a resource to our XAML control so that we can use it throughout the control later:

   1: <UserControl.Resources>
   2:     <converter:Formatter x:Key="FormatConverter" />
   3: </UserControl.Resources>

Now if we go back to our XAML where we are data binding the date we can implement this and pass in the converter parameter (format) we want to use.  The end result full XAML looks like this:

   1: <UserControl x:Class="TypeConverter_CS.Page"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:converter="clr-namespace:TypeConverter_CS"
   5:     Width="400" Height="300">
   6:     <UserControl.Resources>
   7:         <converter:Formatter x:Key="FormatConverter" />
   8:     </UserControl.Resources>
   9:     <Grid x:Name="LayoutRoot" Background="White">
  10:         <ListBox x:Name="FeedList">
  11:             <ListBox.ItemTemplate>
  12:                 <DataTemplate>
  13:                     <StackPanel Orientation="Vertical">
  14:                         <TextBlock FontFamily="Arial" FontWeight="Bold" Foreground="Red" Text="{Binding Title.Text}" />
  15:                         <TextBlock FontFamily="Arial" Text="{Binding PublishDate, Converter={StaticResource FormatConverter}, ConverterParameter=\{0:M\}}" />
  16:                     </StackPanel>
  17:                 </DataTemplate>
  18:             </ListBox.ItemTemplate>
  19:         </ListBox>
  20:     </Grid>
  21: </UserControl>

Notice how we made a reference to our StaticResource (using the key name we provided) and then passed in the ConverterParameter of {0:M} to format our date.  The resulting output is now:

And you’ll notice the date formatting.  Now in our converter we could have been real explicit in our Convert function and looked for a date and converted it specifically, but our converter code is generic enough that it can handle some other input types like more complex date formats or numbers.  If we used this same converter code on a number we could pass in the ConverterParameter of {0:c} for currency formatted information.

If you use Expression Blend as well, you can also use some of the user interface properties to specify the binding values that will get output as XAML…here’s a screenshot of the converter settings UI in blend:

This method is useful when you may have custom conversion needs for your data.  Hope this helps!  You can download this sample here: TypeConverter_CS.zip