Silverlight 2.0 Cross Domain Calls

I was just reading Scott Guthries blog post about silverlight 2.0 and I came across a section discussing how Silverlight will be able to do cross domain calls. I have been very curious how they were planning on solving this one without risking the security of silverlight.

It turns out that all you need on the remote domain is an XML policy file that will allow applications to call your domain directly. It seems that this is how flash has been doing it for a while now and silverlight 2.0 will also respect flash policy files.

Flash vs. Silverlight, Indeed

I was just looking at and decided to put in Flash vs. Silverlight. The results are pretty interesting:

At the time of this posting flash goes from 0% in May ’05 to about 100% in Sept ’07 while silverlight has gone from 0 at May ’07 to 1,300% in Oct. ’07. I guess we can see that Microsoft has done a good job of getting people excited about Silverlight. Now all they need to do is devliver the goods.

Also, one other interesting thing is how F# creates a graph that sort of looks like the New York skyline:

That seems pretty ironic from a functional language.

Dynamic Templated TreeViewItem in WPF

I struggled with this for a long time for some reason so I decided to post a simple example here for everyone who may be encountering the same thing. The scenario I have here is when you have a treeview with several hardcoded treeview items and at the lowest levels of leafs you have them bound to some data provider. The trick is trying to dynamically bind the treeview items to different data templates based on some criteria.

The real example was to have a label and a text box for the dynamic items based on whether you are trying to edit it or not. The trick turned out to be to wrap your DataTemplate in a control and use styling to dynamically switch it.

 Download Sample Project










   <ControlTemplate x:Key=”SelectedTemplate” TargetType=”{x:Type Control}”>

    <Label Content=”{Binding XPath=title}” Foreground=”Red” FontWeight=”Bold”  />


   <ControlTemplate x:Key=”DefaultTemplate” TargetType=”{x:Type Control}”>

    <Label Content=”{Binding XPath=title}” />


   <DataTemplate x:Key=”template”>

    <Control Focusable=”False”>


      <Style TargetType=”{x:Type Control}”>

       <Setter Property=”Template” Value=”{StaticResource DefaultTemplate}” />                           


         <Trigger Property=”IsMouseOver” Value=”True”>

          <Setter Property=”Template” Value=”{StaticResource SelectedTemplate}” />







    <XmlDataProvider x:Key=”justnbusiness” Source=”; />           

















     Source={StaticResource justnbusiness},


    ItemTemplate=”{StaticResource template}”

    Header=”Blog Posts”/>



















Twin Cities Code Camp Spring 2008

I will be giving another talk at the next Twin Cities Code Camp about Visual Studio integration. The event is on April 5th and is free so you should definitely come down and make me sweat with questions that I cannot answer!

I plan on talking about visual studio integration in general but I will hopefully show off the current state of the NBusiness 3 plugin as well.


Tomorrow night (Thursday, 2/21/08) is the next XNA Twin Cities User Group meeting and I will be giving a presentation on the MinMax algorithm in Drop In. It should be pretty fun, there will be some pizza and swag (including some xbox games) and a few other speakers talking about some other interesting AI topics. If you’re in the area you should definitely stop in and learn about XNA!

Here is the main link

And be sure to RSVP so we can guage how many people will be there and get the appropriate amount of pizza.

NBusiness 3 Updates

I’ve been working on NBusiness a little bit over the weekend. I’ve decided to create a Curried API using extension methods for the CodeDom to speed along template creation. Here is an example of what I have so far.

CodeMethodReferenceExpression onPropertyChanged =
 new CodeMethodReferenceExpression(null, “OnPropertyChanged”);
CodeMemberProperty memberProperty = new CodeMemberProperty();
memberProperty.Name = field.Name.ToPascalCase();
memberProperty.Type = new CodeTypeReference(field.Type);
Trust me, as ugly as the above seems it’s still a million times better than doing it all the way it was originally written. Hopefully this will mature and get better over time as well. Here is an example of the code it produces.
private int Aid {
 get {
   return _aid;
 set {
   if ((_aid != value)) {
      _aid = value;
Secondly I have been polishing and simplifying the model framework that comes with NBusiness. I have been working to create an abstract DataAccess API that can easily produce any type of query. Here is an example of how you might insert a new model with the next version of NBusiness.
MockModel model = new MockModel();
model.Name = “testinsert”;
This is as normal and will end up calling into MockModel’s “InsertModel” method which may be implemented like so
protected override void InsertModel(IQuery query)
query.Parameter(“@Id”).Direction = ParameterValueDirection.Output;
query.Parameter(“@Name”).Value = Name;
query.Load += loader =>
   Id = (int)query.Parameter(“@Id”).Value;
The DataBase.Table and DataBase.Name members are code generated, static ITable and IColumn fields based on your E# model definition. The query object will be passed up to parent objects and down to child objects and will be passed into an abstract provider which will use it to generate SQL and call your database. The IQuery object actually comes from your IDatabaseProvider and may abstract it to work with different databases. My theory at this point is that you could actually parse the query object anyway you like in the IDatabaseProvider and with a little manual work you could even get it working across a webservice.
Here is my MockDatabaseProvider for my unit tests. The provider interface is much simpler with this new technique.
class MockDatabaseProvider : IDatabaseProvider
#region IDatabaseProvider Members
 public IQuery Query()
    return new SqlQuery();
 public ITable Table(string name)
   return new SqlTable(name);
 public void Execute(IQuery query)
   MethodCall.Calls.Add(new MethodCall(
      new { Name = “query”, Value = query }));
   SqlQuery sqlQuery = query as SqlQuery;
    // Simulate setting the identity parameter after an insert
    IParameterValue id = sqlQuery.Parameters.FirstOrDefault(
      v => v.Name == “@Id”);
    if (id!=null && id.Direction == ParameterValueDirection.Output)
      id.Value = 100;
    sqlQuery.OnLoad(new MockLoader());