Archive for the ‘Silverlight 4’ Category

Interview of BASTA is online

Monday, January 3rd, 2011

September last year I gave a talk at the BASTA-conference in Mainz about Silverlight 4 and WPF in .NET 4.0. I also gave an interview about Silverlight. You can watch it here: http://it-republik.de/dotnet/news/Einem-WPF-und-Silverlight-Experten-auf-den-Zahn-gefuehlt-057911.html

GUI & Desgin Konferenz – Slides

Wednesday, December 8th, 2010

An der GUI & Design-Konferenz in Nürnberg durfte ich heute zwei Vorträge zu den Themen “Controls in WPF/Silverlight designen und entwickeln” und “Hardwarenahe Programmierung in WPF/Silverlight mit Pixelshadern” halten. Bei Ihnen als Teilnehmer möchte ich mich an dieser Stelle recht herzlich für das grosse Interesse und die Aufmerksamkeit bedanken. Ich hoffe, es hat Ihnen gefallen und Sie konnten das ein oder andere für die Praxis mitnehmen.

Zum Runterladen der versprochenen Slides klicken Sie bitte einfach auf einen der beiden Vorträge:

Viel Spass damit. Falls weitere Fragen auftauchen oder der Code zu den kurzen Live-Demos gewünscht ist, genügt eine kurze Mail an mich. Schreiben Sie mir auch, falls Sie individuelle Trainings oder Consulting im Bereich WPF/Silverlight benötigen: Mail an Thomas

Cheers,
Thomas

BASTA! Conference – Silverlight 4 – vier gewinnt

Wednesday, September 22nd, 2010

Nach anfänglichen Schwierigkeiten mit dem WLAN – wahrscheinlich ein defektes WLAN-Kabel ;-) – hat der Upload nun endlich geklappt. Anbei finden Sie die live programmierten Demos und die Slides zum Vortrag. Viel Spass damit und Happy Coding.

Slides und Demos.

image

WPF book has been released and Silverlight book will be available on 28th of August

Monday, July 12th, 2010

Exactly two years after the first release of the WPF-book the second edition is available since some days. Find more details about the content and where you can order it on http://www.thomasclaudiushuber.com/wpf.

The Silverlight-Book has also been written and is currently running through the process of reading, testing and printing. It will be in stores on 28th of August. Find more information about the Silverlight-Book and where you can order it on http://www.thomasclaudiushuber.com/silverlight.

I hope you like the books and you can master the “programming-challenge” of your wpf- and silverlight-projects with the knowhow you got from the books.

Cheers,
Thomas

Visual Studio has been released, Silverlight 4 has been released and the books are on their way…

Saturday, April 17th, 2010

After Visual Studio has been released on Monday this week, Silverlight 4 is also available since Thursday. I’ll have to speed up my book-writing. As many of you know, I’m writing on a second edition of my WPF-book to .NET 4.0 and Visual Studio 2010. I’m also writing on a Silverlight-book (about Silverlight 4.0). Below some details of the two books.

The WPF-Book:

I’ll finish the update of my WPF-book till end of April, so it’ll be released in June. There are many new things in it, like a section to the Model-View-ViewModel-Pattern, Multitouch, the new Controls DatePicker, Calendar and DataGrid, Animation Easing-Functions, VisualStateManager, Windows 7 Taskbarintegration, Pixel-Shaders and much more. Of course there’s also a new version of the FriendStorage-Application that is using new features and controls, like e.g. the DataGrid:

01_06

FriendStorage now also has integration into the Windows 7 Taskbar. So you can iterate through the friends via the Buttons shown in the Windows 7 Taskbar Thumbnail. Also recognize that the image of the current friend is also displayed as overlay-image on the Taskbar-Button

image 

You find the second edition of my WPF-book here on amazon.de

The Silverlight-book

I’ll write on the Silverlight-book till end of June, so it’ll be released in August. I hope you’re looking forward to it. I gave and will give my best that it’s a great resource to all professional Silverlight-Developers and those who want to become one of those. In May I’ll show the contents of the Silverlight-book on my homepage. I’ll also blog here. For now I can say that there’s a FriendStorageOnline-Application in the Samples with Login/Registration and CRUD-Operations via WCF Ria Services. A logged-in User can create Friendlists and insert data as usual. The app looks like this:

01_04

The Silverlight-book is also already on amazon here. But keep in mind that there could be a change in pages (some more up to 1000) and so maybe also in price. I’ll post more information about the targeted pagecount in May, then you’ll also see some details of the contents.

Ciao,
Thomas

Silverlight 4 Release Candidate is here

Monday, March 15th, 2010

The Mix has started some hours ago, and here it is, the Silverlight 4 Release Candidate. Now you can move your development-environment from Visual Studio 2010 Beta to RC. There are also updates to WCF RIA Services, a WCF RIA Services Toolkit etc. Find everything you need here:

http://www.silverlight.net/getstarted/silverlight-4/

There’s also a fantastic post from Tim Heuer about the changes in the Silverlight RC here:

http://timheuer.com/blog/archive/2010/03/15/whats-new-in-silverlight-4-rc-mix10.aspx

Another great thing is that Silverlight 4 is THE technology for Windows Phone 7. So I think I’ve to sell my iPhone and buy me a new Mobile with Windows Phone 7 on it. If you want to start developing Mobile-apps with Silverlight, also go to Tim Heuers blog: http://timheuer.com/blog/archive/2010/03/15/get-started-with-silverlight-for-windows-phone.aspx

So have fun with the new release. I’ll go downstairs in my dark room now and finish up my Silverlight 4.0 book. It’ll take a while. For now I can say if you like my WPF-book, you’ll love that Silverlight book for sure. :)

Visual Studio 2010 RC and Silverlight 4 Beta

Tuesday, February 9th, 2010

Yesterday Visual Studio 2010 RC was released to MSDN Subscribers (find the link here), tomorrow it’s available for download for everyone. The performance is great as far as I can say by using it for at least one day. But it lacks on support for Silverlight 4 Beta.

If you’re developing Silverlight 4 applications, it is recommended that you stay on Visual Studio 2010 Beta 2 until new bits of Silverlight come out. “New bits of Silverlight” means a Silverlight Release Candidate. It is expected also for this month. Wow, how the time is ticking away. I just thought it has been some days ago since I read Dr. Tim Sneaths post about the Silverlight 1.0 RC, and now we’ll have the 4.0 Release Candidate soon.

The more I work with Silverlight 4.0, the more I love this Plugin. While I missed some things like e.g. implicit Styles and basedOn Styles in version 2.0, version 4.0 now contains both of them. Also printing is supported, WebCam- and Microphone-Access, Com-Interop for Out-Of-Browser apps etc. And the most important aspects for Business-Apps, Data-Access, Validation etc. are easy to do. With WCF RIA Services (formerly .NET RIA Services) you’ve a great framework for building Business apps. Also I’ve to say that I’m a total fan of the REST-based WCF Data Services (formerly ADO.NET Data Services), which are now also included in Sharepoint 2010. Silverlight contains a small Client API for accessing those services and make the classical CRUD-operations.

Silverlight 4.0 contains many great features to build really powerful apps. But not yet with Visual Studio 2010 RC. As soon as the new Silverlight-bits will be available, you’ll read it here.

How to print a List<string> in Silverlight 4 Beta over multiple pages?!

Thursday, December 10th, 2009

On www.silverlight.net several people are asking how to print the values of a DataGrid in Silverlight. You cannot just assign the DataGrid to the PageVisual-Property of the PrintPageEventArgs. This would just print the DataGrid as it is on one page. The data wouldn’t be splitted on several pages, cause there’s no paging logic to use. You’ve to write this logic.

You’re responsible for the paging! But how to do it? In this post I’ll give you a little idea how it could work by simple printing out a List of string-values. I won’t talk a lot about the details. Just look at the code below:

public partial class MainPage : UserControl
{
  private List<string> _list;
  private const double ROWHEIGHT = 20;
  private const double PAGEMARGIN = 30;
  public MainPage()
  {
    InitializeComponent();
    _list = new List<string>();

    for (int i = 1; i < 101; i++)
    {
      _list.Add(i + " thanks to Thomas for this printing sample");
      _list.Add("Visit http://www.thomasclaudiushuber.com");
    }
  }

  private void Button_Click(object sender, RoutedEventArgs e)
  {
    _currentIndex = 0;

    var pd = new PrintDocument();
    pd.DocumentName = "AListFromThomas";
    pd.PrintPage += pd_PrintPage;
    pd.Print();

  }

  private int _currentIndex;
  private double _currentTop;
  private double _availableSpace;
  void pd_PrintPage(object sender, PrintPageEventArgs e)
  {
    var pageRoot = new Canvas();
    e.PageVisual = pageRoot;

    _currentTop = PAGEMARGIN;
    _availableSpace = e.PrintableArea.Height - PAGEMARGIN*2;
    while (_currentIndex < _list.Count)
    {
      var txt = new TextBlock { Text = _list[_currentIndex] };

      if (ROWHEIGHT > _availableSpace)
      {
        e.HasMorePages = true;
        break;
      }

      txt.SetValue(Canvas.TopProperty, _currentTop);
      txt.SetValue(Canvas.LeftProperty, PAGEMARGIN);
      pageRoot.Children.Add(txt);
      _currentTop += ROWHEIGHT;
      _availableSpace -= ROWHEIGHT;
      _currentIndex++;
    }
  }
}

When the Button_Click-Eventhandler is executed, the List gets printed over 5 pages. You can easily print it to PDFCreator or XPS Printer to test it. The output looks like this:

image

Download the source here and enjoy. Give me feedback by entering a comment to this blogentry or via email on www.thomasclaudiushuber.com/blog.

How to print dynamically created Images in Silverlight 4 Beta

Wednesday, November 25th, 2009

Silverlight 4 supports printing scenarios. It’s quite easy. Just create a PrintDocument instance, handle the PrintPage-Event and call the Print-Method. In the PrintPage-Event set the PageVisual-Property of the PrintPageEventArgs to a UIElement of your choice. If there are more pages, set the HasMorePages-Property of the PrintPageEventArgs to true and the PrintPage-Eventhandler would be called again for the next page.

Below a simple example using a lambda expression. When the Print-Method is called a PrintDialog is displayed to the User, where he can select the printer of his choice. When the PrintDialog was accepted, the PrintPage-Event gets fired and the lambda expression below get’s called. The PageVisual-Property is set to a TextBlock. So that TextBlock with the text “Thoams says…” is printed out.

var pd = new PrintDocument();
pd.PrintPage += (s, e) =>
  {
    e.PageVisual = new TextBlock {Text="Thomas says Hello"};
  };
pd.Print();

Ok, so far so good. As I was working on an example for my upcoming Silverlight 4 book I needed to create an Image-Element on the fly and print this out. And then I noticed that the Image doesn’t appear on the output.

While searching for a solution I found somebody having the same problem in this thread in Microsoft’s Silverlight forums:

http://forums.silverlight.net/forums/t/145680.aspx

So, it seemed it was not my cause, it was a Beta-cause. So let’s look at a workaround. But first look at the bug.

I made a smaller example to reproduce it. View the following code. What do you think is printed on the page?

void PrintButton_Click(object sender, RoutedEventArgs e)
{
  var streamResourceInfo =
    Application.GetResourceStream(
      new Uri("thomas.png", UriKind.Relative));

  var bitmapImage = new BitmapImage();
  bitmapImage.SetSource(streamResourceInfo.Stream);

  var image = new Image
  {
    Width = bitmapImage.PixelWidth,
    Height = bitmapImage.PixelHeight,
    Source = bitmapImage
  };

  var pd = new PrintDocument();
  pd.PrintPage += (s, args) =>
    {
      args.PageVisual = image;
    };
  pd.Print();
}

Right, an Image should be printed on the page. But it isn’t. The page is empty. Well, the next thing I tried was to call Measure, Arrange and UpdateLayout on the Image to force a layout-pass. But anyway, it didn’t work, the printed page is always empty.

When the Image isn’t created on the fly, it works. Define the Image in XAML like this

<Image Source="thomas.png" x:Name="image"/>

and a Print-Method in the Codebehind-File would work like that:

void PrintButton_Click(object sender, RoutedEventArgs e)
{
  var pd = new PrintDocument();
  pd.PrintPage += (s, args) =>
    {
      args.PageVisual = image;
    };
  pd.Print();
}

But we want to print an Image on the fly. So how to do that? One way I found out was to create an ImageBrush and set its ImageSource-Property to the BitmapImage. Use the ImageBrush for a Rectangle’s Fill-Property and print out that Rectangle. So here is some code to dynamically print an image by using an ImageBrush in combination with a Rectangle:

void PrintButton_Click(object sender, RoutedEventArgs e)
{
  var streamResourceInfo =
    Application.GetResourceStream(
      new Uri("thomas.png", UriKind.Relative));

  var bitmapImage = new BitmapImage();
  bitmapImage.SetSource(streamResourceInfo.Stream);

  var imageBrush = new ImageBrush();
  imageBrush.ImageSource = bitmapImage;

  var rectangle = new Rectangle
  {
    Width = bitmapImage.PixelWidth,
    Height = bitmapImage.PixelHeight,
    Fill = imageBrush
  };

  var pd = new PrintDocument();
  pd.PrintPage += (s, args) =>
    {
      args.PageVisual = rectangle;
    };
  pd.Print();
}

And voilà, the output looks like this when printed to my PDFCreator-Printer:

image

[Download the Source]

Cheers Thomas