Archive for the ‘Silverlight-Book’ Category

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

Friday-Evening Fun with Silverlight’s Animation Easing Functions

Friday, April 30th, 2010

This weekend I’ve to finish the second edition of my WPF-book. Luckily it’s going to rain tomorrow. But I’ve almost done it. This evening I’ve just ported a small sample for Animation Easing Functions from WPF to Silverlight. It was easy, all I had to do was using a PathGeometry instead of the not existing StreamGeometry to draw the lines of the functions. Use the fun-sample below to play around with these easing functions. You’ll get the code of this version with my upcoming german Silverlight-Book in August. So have fun, 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

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

Hey Thomas, what’s coming up next?

Saturday, October 31st, 2009

I’ll give you just a short information of what is coming up next and what I did the last months. Let’s start with the things coming up…

… what’s coming up next:

  • WebTech-Conference – 16th November, Karlsruhe/Germany
    Another talk about datadriven Silverlight-Applications. Meet me at this conference for discussions about WPF, Silverlight, .NET in general, my books and other topics. Find more about the WebTech-conference on webtech
  • Update of the WPF-book to .NET 4.0 and Visual Studio 2010
    The WPF-book was written about .NET 3.5. Next year .NET 4.0 will be released. There are many new things introduced in WPF. The DataGrid- and DatePicker-Control, VisualStateManager, Animation Easing Functions, Layout Rounding and so on. I’m working on an update of the book that will be released next year shortly after the German Visual Studio Release.
  • Writing a german book about Silverlight 4
    Currently I’m working hard on my book about Silverlight 4. I’ve already written about 300 pages. The book will be released next year shortly after the Silverlight 4 release. There are no comments on the Silverlight 4 release, but at PDC in mid-November there’s a session about the Silverlight-Roadmap. Then we’ll know more. So stay tuned. Find more about the upcoming Silverlight-Book on the new silverlight-category on my homepage

… what I did the last months:

  • Silverlight-Articles
    I’ve written six articles about Silverlight for the German dotnet-magazine. Download the articles beside others on www.thomasclaudiushuber.com/articles.php.
  • PrioConference – 28th October, Munich/Germany
    I had a session about datadriven Silverlight-Applications. Find the Details on the new talks-category on my homepage.

So stay tuned. If you’ve any questions, leave a comment or write me an email via the contact-form on my homepage.

Thomas