Mar 25

I am going to show you how you can modify the standard ListBox control used in Silverlight 2.0. Many people want to change the default view of this control but they can’t remove the line between the items. If you download the code of the Silverlight control from the official site of Microsoft you will see that after every item there is a line. In this example I will show you how you can remove this line.

Let’s create e new Silverlight 2.0 application and place a ListBox in it.

<ListBox>
    <ListBox.Items>
    <ListBoxItem Content="I am the first item in the collection" />
    <ListBoxItem Content="I am the second item in the collection" />
  </ListBox.Items>
 </ListBox>

Read the rest of this entry »

Mar 7

SilverlightIn MIX Conference 2008 Microsoft presented Silverlight 2.0 beta 1. Here is a list of new features in this release:

  • WPF UI Framework
    Silverlight 2 includes a rich WPF-based UI framework that makes building rich Web applications much easier. In includes a powerful graphics and animation engine, as well as rich support for higher-level UI capabilities like controls, layout management, data-binding, styles, and template skinning. The WPF UI Framework in Silverlight is a compatible subset of the WPF UI Framework features in the full .NET Framework, and enables developers to re-use skills, controls, code and content to build both rich cross browser web applications, as well as rich desktop Windows applications.
  • Rich Controls
    Silverlight 2 includes a rich set of built-in controls that developers and designers can use to quickly build applications. This upcoming Beta1 release includes core form controls (TextBox, CheckBox, RadioButton, etc), built-in layout management panels (StackPanel, Grid, Panel, etc), common functionality controls (Slider, ScrollViewer, Calendar, DatePicker, etc), and data manipulation controls (DataGrid, ListBox, etc). The built-in controls support a rich control templating model, which enables developers and designers to collaborate together to build highly polished solutions.
  • Rich Networking Support
    Silverlight 2 includes rich networking support. It includes out of the box support for calling REST, WS*/SOAP, POX, RSS, and standard HTTP services. It supports cross domain network access (enabling Silverlight clients to directly access resources and data from resources on the web). Beta1 also includes built-in sockets networking support.
  • Rich Base Class Library
    Silverlight 2 includes a rich .NET base class library of functionality (collections, IO, generics, threading, globalization, XML, local storage, etc). It includes rich APIs that enable HTML DOM/JavaScript integration with .NET code. It also includes LINQ and LINQ to XML library support (enabling easy transformation and querying of data), as well as local data caching and storage support. The .NET APIs in Silverlight are a compatible subset of the full .NET Framework.

The SDK for Silverlight 2.0 beta 1 is already available at its website.

Mar 2
Lambda Expressions
icon1 Boyan Mihailov | icon2 C# | icon4 03 2nd, 2008| icon3No Comments »

In C# 2.0 there are anonymous methods, which allows you to write your method code inline instead of creating a new method in your class. In C# 3.0 there is a new feature - lambda expressions. The goal of this expressions is the same as the anonymous methods, but the syntax is more concise.

Let’s have the following code:

class LambdaExpressionTest
{
  public delegate int myDelegate(int x);

  static void Main()
  {
    myDelegate testFunc = new myDelegate(LambdaExpressionTest.myFucn);
    Console.WriteLine(testFunc(5)); // returns 23
  }

  public static int myFucn(int x) { return x * x - 2; }
}

If we want to rewrite this code using anonymous method, it will get the following look:

class LambdaExpressionTest
{
  public delegate int myDelegate(int x);

  static void Main()
  {
    myDelegate testFunc = new myDelegate(delegate(int x) { return x * x - 2; });
    Console.WriteLine(testFunc(5));
  }
}

And if we want to rewrite this code using lambda expressions, it will look like this:

class LambdaExpressionTest
{
  public delegate int myDelegate(int x);

  static void Main()
  {
    myDelegate testFunc = x => x * x - 2;
    Console.WriteLine(testFunc(5));
  }
}

Isn’t it so simple? :) The sign ‘=>‘ is read as “goes to”. We first indicate the arguments of our method and after that we do our calculations in it.