Balder gets declarative

We're getting closer to the BETA mark for Balder, and we're starting to get most of the features we want in for version 1 ready. The latest feature is the ability to declaratively through Xaml get Balder up and running. Current release is versioned 0.8.7 and can be found over at the Balder page at Codeplex.

By adding the following namespace declaration in your Xaml file:

xmlns:Core="clr-namespace:Balder.Core;assembly=Balder.Core.Silverlight" 

You now get a set of extra controls that can be used.

First off is the RenderingContainer:


<balder:RenderingContainer x:Name="_renderingContainer" Width="800" Height="600" BackgroundColor="Black"/> 
 

You need to specify the Width and Height, as that is used to setup the display properly. The BackgroundColor property can be any color, including transparent – which is great if you want to mix with existing Silverlight controls on your page. 

The next control we've added is the Mesh control, it enables you to add any Mesh from a file/resource to the RenderingContainer. You do this by accessing the Nodes property on the Container and putting up a RenderedNodeCollection and put your Mesh(es) within that.


<balder:RenderingContainer.Nodes>
       <balder:RenderedNodeCollection>
             <balder:Mesh x:Name="_audi" AssetName="audi.ASE"/>
        </balder:RenderedNodeCollection>
</balder:RenderingContainer.Nodes>
 

For now, there is a limited amount of DependencyProperties exposed, so manipulation via Storyboards aren't possible today, but will be very soon. The only way to access this is by hooking up the Updated event on the RenderingContainer and implement codebehind logic for it, something like this:


private float _angle = 0f;

private void Updated(RenderingContainer renderingContainer)
{
    _audi.Node.World = Matrix.CreateRotationY(_angle);
    _angle += 0.5f;
    _renderingContainer.Camera.Position = new Vector(0,-5,-20);
}
 

Last but not least, to get it all working, you need to initialize Balder. In your App.xaml.cs file, during the Application_Startup event, you need to add one line of code. It is very important for now that you add that line before your page (RootVisual) is created and set.


  private void Application_Startup(object sender, StartupEventArgs e)
  {
   TargetDevice.Initialize();
   RootVisual = new Page();
  }

I you want to use it the "conventional" way – non Xaml based, you need to add a similar line of code, but that line of code needs to be added after the page has been created. This is something that makes absolutely no sense and is something we're trying to fix and make it a lot more sense. Our goal is to get rid of that line of code all together.

A little note, we're not trying to mimick the WPF 3D namespaces at all, we're going our own direction. We don't feel the urge to replicate those, as the purpose of Balder is very different. 

8 thoughts on “Balder gets declarative

  1. Great work !

    It takes a lot of effort to get a full declarative (XAML) API up and running… Next step 3D drawing primitives in XAML and then full databinding against ObservableCollection<T> with DataTemplates ? Just dreaming, but wouldn’t mind that it is part of a 2.0 release.. :-)

    Have fun coding Einar ! Stefaan

  2. Thanks.

    Full Xaml support will take a while, but I will be focusing a bit on getting some of the stuff up and running. Databinding is one of the things I’d like to get up and running, not sure what DataTemplates could be used for – please enlighten me.

    Primitives would be possible to do, then you’d have something similar to what WPF has – adding vertices and faces manually. I have to think that one over.

  3. I don’t know the DataTemplate is a good idea, have to think this over too. But to give an example, to create the ‘data-point’ part of a 3D scatterplot (like http://en.wikipedia.org/wiki/File:Scatter_plot.jpg), one would use a DataTemplate like :

    <DataTemplate>
    <Point3D X="{Binding Total_Enery}" Y="{Binding Gass_Energy}" Z="{Binding Density}" Color="{Binding Temperature}" Radius="1"/>
    </DataTemplate>

    That could be bound to an ObservableCollection so that points can appear and disappear and they could even change position when they implement INotifyPropertyChanged.

    But I don’t know whether this is a good idea for two reasons :
    1) It would be wise to use Balder for a 3D scatterplot like this ?
    2) The ScatterSeries of the Silverlight toolkit Chart control doesn’t have a DataTemplate. I have to look into how they allow one to customize the plotted points.

    Have fun coding, Stefaan

  4. Thanks for the input.

    It gives me a couple of other ideas.

    I will focus a bit more on the Xaml version of Balder – love to get more input and needs for Xaml support.

  5. Just read a blog post about the Silverlight Virtual Earth control, seems that one works with the ItemsSource/ItemTemplate approach : http://davidburela.wordpress.com/2009/11/02/databinding-shapes-with-the-bing-maps-control-for-silverlight/

    And will now stop bothering you… :-) Stefaan

  6. That is cool.

    I can see a lot of potential with this for doing some cool 3D repeaters.. :)

    And, please "bother" me. It is no bother – love to get input like this!

  7. Mark Roebuck says:

    I’m having problems with this. I get a "Assembly Balder.Core.Silverlight was not found" error message. It doesn’t seem to be in the 8.7 download and consequently all the extra set of controls are unrecognised.

  8. Hi,
    I’ve heard several reports about this. Thanks for pointing it out.
    I’m investigating why it has the " it works on my machine" syndrome. There might be something wrong in my NANT build script that produces the release versions of the libraries.

    We’re closing in on a new release soon, hopefully I’ll get the time to fix this and more that release.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: