This article gives brief explanation about Silverlight 4. If you’re looking for Silverlight 4 hosting, you can get the professional hosting at ASPHostDirectory. Only with $ 3.99/month to get SL 4 hosting. What are you waiting for?

One of the cool new features in Silverlight 4 is the ability to data bind to indexed properties. This means that even if you don’t know at design time what properties you data object has you can still data bind to them.

The syntax is very similar to a normal data binding, only in this case you need to use the [key] syntax instead. For example in example below the FirstName is a regular property while the LastName below is an indexed property.

<StackPanel Name="LayoutRoot"> 
    <StackPanel Orientation="Horizontal" Margin="1"> 
        <TextBlock Text="FirstName" Width="150"></TextBlock> 
        <TextBox Text="{Binding FirstName, Mode=TwoWay}" Width="500"></TextBox> 
    </StackPanel> 
    <StackPanel Orientation="Horizontal" Margin="1"> 
        <TextBlock Text="LastName" Width="150"></TextBlock> 
        <TextBox Text="{Binding [LastName], Mode=TwoWay}" Width="500"></TextBox> 
    </StackPanel>
</StackPanel>

Creating the class to data bind to is simple. All you need to do is add a property with the following syntax:

public object this[string key] 
    { get; set; }

In this example we are using a Peron class with a regular FirstName property and all others are dong using indexed properties. The complete class, including INotifyPropertyChanged looks like this:

public class Person : INotifyPropertyChanged

    public Person() 
   
        PropertyChanged = (s, e) => { };

        FirstName = "Maurice"; 
        this["LastName"] = "de Beijer";
        this["BabyName"] = "Kai"; 
    }

    private Dictionary<string, object> _data = new Dictionary<string, object>(); 
    public object this[string key] 
   
        get 
       
            if (!_data.ContainsKey(key)) 
                _data[key] = null;

            return _data[key]; 
       
        set 
       
            _data[key] = value; 
            PropertyChanged(this, new PropertyChangedEventArgs("")); 
       
    }

    public IEnumerable<string> Keys 
    {
        get 
        {
            return _data.Keys; 
        }
    }

    private string _firstName; 
    public string FirstName
   
        get
       
            return _firstName;
       
        set 
       
            _firstName = value; 
            PropertyChanged(this, new PropertyChangedEventArgs("FirstName")); 
       
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

While not having to know the objects structure at design time is nice but in the XAML above we still hard coded the data bindings so that doesn’t buy us much yet. So fully utilize this we need to dynamically generate the UI as well. Fortunately that is quite easy to do with the following code:

void MainPage_Loaded(object sender, RoutedEventArgs e)

    var person = new Person(); 
    DataContext = person; 
    foreach (var item in person.Keys) 
   
        var lbl = new TextBlock(); 
        lbl.Text = item; 
        lbl.Width = 150;

        var txt = new TextBox(); 
        var binding = new Binding("[" + item + "]"); 
        binding.Mode = BindingMode.TwoWay; 
        txt.SetBinding(TextBox.TextProperty, binding); 
        txt.Width = 500;

        var line = new StackPanel(); 
        line.Orientation = Orientation.Horizontal; 
        line.Children.Add(lbl); 
        line.Children.Add(txt); 
        line.Margin = new Thickness(1); 
        LayoutRoot.Children.Add(line); 
    }
}

And now you can see the result. Try it!
Happy Programming!

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!