Skip to main content
/_layouts/images/titlegraphic.gif

Peter Himschoot's Windows Foundation Trilogy

Go Search
Peter Himschoot's Windows Foundation Trilogy
U2U Website
  

Talking about .NET, Windows Presentation Foundation, Workflow Foundation and Communication Foundation

 Image Web Part

Peter at U2U booth during TechEd Eur 2006
  U2U Home
  U2U Course Calendar
Talking about .NET, Windows Presentation Foundation, Workflow Foundation and Communication Foundation
Chopstick Noodle

A while a go I created a bunch of video’s for Microsoft Belgium chopsticks site.

Next week I’ll be doing a bit of Windows Live training, and of course I want to show the Silverlight Streaming Service, plus a number of plugins, like to one for windows live.

So here it is, the demo :)

VS2008 SP1 is Live! (RTM)

Good news, MS has published SP1

If you installed on of the pre-releases you need to de-install them with this

Then you can download the installer here.

Oh, and if you’re into Silverlight you’ll need to install the Silverlight tools update

Have fun installing, I know I will tomorrow!!

Composite Application Guidance for WPF
Microsoft P&P has recently released a WPF guidance, similar to the CAB for winforms.
 
Find it here
Debugging with source
I must say, one of the things I really like in Visual Studio 2008 now is the debugging with sources feature, allowing you to see the source of the .NET framework. Currently most of the base framework is available, and so is WinForms/WPF/... More to come.
 
I really like this because now I can learn more about the inner working of the framework and why my code is behaving in a certain fashion. Before you could also do this, using Reflector, but seeing the orginal sources with full local variable names is a lot more practical.
 
I do confess, when I am on the road the feature does require an active internet connection (because it checks to see if a newer version of the source is available, I think) and I do think it should work without a connection. Next version please :)
 
And it is soo easy to setup.
 
 
DevDays NL
Yesterday I gave two sessions @ DevDays NL:
 
On was a Silverlight End to End application, about belgian beers ;)
 
The other was on using REST and JSON with WCF
 
Both can be found here
(oeps, looks like the link dropped off)
 
MSDN ChopStick Noodles

I am happy to announce that I've started a series of screencasts called ChopStick Noodles (you eat noodles with chopsticks, don't you? J).

The first two are about the background worker (for which I've previously written an article) and about creating your own code snippets.

There is also a third one about improvements in Visual Studio 2008 for using datasets in enterprise development, but that one hasn't been published.

If you have suggestions for future screencasts, please let me know (why not add a comment J).

I'm thinking about one on Isolated Storage, one on XAML, and a series on Silverlight.

Hilarious movie about Silverlight!!!

Silverlight Rehab! Watch it here!!!

Silverlight 2.0 DataBinding Explained (a bit) :)

 

Silverlight supports data binding, but currently there is a lack of samples explaining some of the nicer concepts, plus some of the things are not as you might expect.

Data binding in Silverlight is through the {Binding <Path>} syntax, for example to bind a TextBox's Text property to the Value property of some class you would use

<TextBox Text="{Binding Value}"  />

The catch is that this is a one way binding, if you change the Text in the TextBox the Age property doesn't get updated...

The solution is simple, you need to set the Mode property of the Binding object to TwoWay like this:

<TextBox Text="{Binding Value, Mode=TwoWay}"  />

Now modifying the Text property will modify the Value property (and vice versa).

Next on my agenda is data conversion. You can do this by using a class that implement the IValueConverter interface, for example:

public class DoubleToBrushConverter  : IValueConverter
{
  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
    string v = (value ?? "0").ToString();
    double cutoff = parameter == null ? 30 : double.Parse( parameter.ToString() );

    if (double.Parse(v) < cutoff)
      return new SolidColorBrush(Colors.Green);
    else
      return new SolidColorBrush(Colors.Red);
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
    throw new NotImplementedException();
  }
}

This class will convert the value to a brush, nice if you want to show the user that an invalid or unusual value was entered. You can use this as follows:

<TextBox Text="{Binding Value, Mode=TwoWay}" 
         Background="{Binding Value, 
                              Converter={StaticResource converter},
                              ConverterParameter=40}" />

The ConverterParameter will get passed into the Convert method as the parameter parameter.

Please note that we don't need to implement the ConvertBack method of the IValueConverter interface because the user will not be able to change the background color.

image

When the value goes above 40 the background turns red.

Last thing is the Source property of the Binding element. With this you can point to some object on your Page, stored as a resource:

<TextBox Text="{Binding Value, 
                  Mode=TwoWay, 
                  Source={StaticResource someObject}}"  />

 

This of course opens up using Element binding, which means binding to elements of your page to each other. The technique I propose is using some temporary object and binding the controls to this object.

For example, to bind three controls (two textboxes and one slider) to each other use following markup:

<TextBox Text="{Binding Value, Mode=TwoWay, Source={StaticResource someObject}}"  />
<TextBox Text="{Binding Value, Mode=TwoWay, Source={StaticResource someObject}}" 
         Background="{Binding Value,
                              Source={StaticResource someObject},
                              Converter={StaticResource converter}, 
                              ConverterParameter=40}" />

<Slider x:Name="theSlider"
  Minimum="0" Maximum="100" SmallChange="1" LargeChange="10"  
  Value="{Binding Value, Mode=TwoWay, Source={StaticResource someObject}}" />

Each binding refers to the same Source, which I've declared on top of the page resources:

<UserControl.Resources>
  <u:DoubleToBrushConverter x:Key="converter" />
  <u:ElementBinding x:Key="someObject" Value="66" />
</UserControl.Resources>

The DoubleToBrushConverter class is the one on top, the ElementBinding class looks like this:

public class ElementBinding : INotifyPropertyChanged
{
  double val;

  public double Value
  {
    get { return val; }
    set { val = value; OnPropertyChanged("Value"); }
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(string propName)
  {
    if (PropertyChanged != null)
      PropertyChanged(this, new PropertyChangedEventArgs(propName));
  }
}

The class implements the standard INotifyPropertyChanged interface to support databinding.

A demo project containing this sample can be found here.

Fun with DeepZoom

I've been experimenting a little bit with DeepZoom, a new extension for Silverlight, currently in beta from microsoft. This works together with the MultiScaleImage control from silverlight, giving you a very performant and smooth picture browsing experience.

It does this by dividing a large image into 256x256 squares and building a pyramid of smaller sized images, again divided into 256x256 squares, up until it reaches a single pixel image. This adds 33% of extra space required on disk, which I believe isn't very much.

This way it can load the squares it needs at the right zoom level, reducing the amount of pixels downloaded (at the same time).

To try this yourself, you first need the the Deep Zoom Composer utility:

http://blogs.msdn.com/expression/archive/2008/03/05/download-the-preview-of-the-deep-zoom-composer.aspx

Start it up and create a new project:

DZ_CreateProj

On the Import tab click the "Add Image..." button and import any picture you want:

DZ_Ïmport

Next click on the Compose tab and position your pictures the way you want:

DZ_Compose

And as the last step export your stuff (first choose a name for your export):

DZ_Export

This will create a directory structure:

Heroes

With Visual Studio 2008, create a new Silverlight project with default settings (with extra web project). Build the project, then copy the above contents into the web project's ClientBin folder (you need to build the project before you will see this folder).

Then in page.xaml first remove the Width and Height properties, then add a MultiScaleImage control with source property pointing to the info.bin file:

 

<UserControl x:Class="DeepZoomDemo.Page"
    xmlns="http://schemas.microsoft.com/client/2007" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid x:Name="LayoutRoot" Background="White">

    <MultiScaleImage Source="info.bin" />

  </Grid>
</UserControl>

Build your project and run. That's it!

Next entry will show how to add Zoom and move support to this solution.

Launch & TechDays Sessions

As promised, my launch and TechDays slides and demos can be found at http://www.u2u.be/res/Peter.aspx.

Simply scroll down to presentations...

1 - 10 Next

 ‭(Hidden)‬ Admin Links