Jojit Soriano's Blog

July 13, 2009

Silverlight 3 Released to Web

Filed under: Silverlight — jojitsoriano @ 9:08 am
Tags:

 The much-awaited release of Silverlight 3 came last Friday, July 10. Read on the following blogs about the release, the installers, and the new features of Silverlight 3:

1. Scott Guthrie’s blog – http://weblogs.asp.net/scottgu/archive/2009/07/10/silverlight-3-released.aspx.

2. Tim Heuer’s blog – http://timheuer.com/blog/

 

I recommend that you read Tim Heuer’s blog because of the more detailed discussion of the new features of Silverlight 3.

 

The links to the installers are listed below but for more information you can visit this website: http://silverlight.net/GetStarted/.

1. Microsoft Silverlight Tools for Visual Studio 2008 SP1

2. Microsoft Expression Blend 3 + SketchFlow RC

3. Deep Zoom Composer

4. Silverlight 3 Toolkit July 2009

5. Offline CHM Documentation

 

Enjoy!

March 30, 2009

March 2009 CTP of Silverlight LOB Controls from Infragistics Now Available

Filed under: Silverlight — jojitsoriano @ 7:25 am
Tags: ,

I know I’m one week late to announce this in my blog. March 2009 CTP of Silverlight LOB controls from Infragistics is now available for download! I’ve been watching out for this as early as the first week of March and I was surprised to read in a blog this morning that the March CTP was released last March 23. I don’t know yet what really are in it but what is significant to know is that this release is built on Silverlight 3 Beta. That’s the main reason I haven’t explored it yet. My project is currently developed in Silverlight 2 and I will have to setup another development environment to test if my source code will work in Silverlight 3 Beta. For the meantime, I’ll just believe while not seeing for myself what’s new based on the following links:

Product Overview: http://www.infragistics.com/Product.aspx?id=7781#Overview

Release Blog: http://blogs.infragistics.com/blogs/devin_rader/archive/2009/03/25/netadvantage-webclient-silverlight-march-2009-ctp.aspx

I know you gonna ask this same question: Why Silverlight 3 Beta for this CTP? Here’s the answer: http://blogs.infragistics.com/blogs/jason_beres/archive/2009/03/27/silverlight-product-version-strategy.aspx

I’ll just wait for the right time to upgrade to Silverlight 3 Beta and that may be as early as next week after demos to the project stakeholders are all done. J

March 4, 2009

Binding Silverlight DataGrid Control to a Dynamically-Created Data Object

Filed under: Silverlight — jojitsoriano @ 7:45 am
Tags: , ,

As a backgrounder, data can be bound to a Silverlight DataGrid control by setting the ItemsSource property to a collection of objects. The object class should have been defined so that each column in the data grid can be bound to a property of the data object. Does it mean that you have to create a class during coding time so that you can bind the instance of that class to the DataGrid? What if you do not know what the field names are and you will just get it from a web service exposed by an existing application?

Sample code in MSDN and some .NET websites shows how to bind the DataGrid to a collection of data objects. This post aims to discuss binding the DataGrid to a collection of “dynamically-created” data objects. Thanks to WJamesLord of the Silverlight.Net forum for the code because of which I was able to solve my problem with the DataGrid binding. Honestly, this was only the second time that I made use of Reflection in my project that I practically copied his code and modified it a little to suit my requirement.

Creating the Class Containing the Fields of the Data Object

Step 1: Create the Class Using Reflection.

AssemblyName an = new
AssemblyName(“Result” + this.GetHashCode());

 


AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);

 

ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(“MainModule”);

    TypeBuilder tb = moduleBuilder.DefineType(<<Name of the Class>>,

    TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass |


TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout,


typeof(object));

ConstructorBuilder constructor = tb.DefineDefaultConstructor(

    MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);

Step 2: Add the Properties by calling this AddProperty method.

AddProperty(“RowNumber”, typeof(int), ref tb);

AddProperty(“FirstName”, typeof(string), ref tb);


private
void AddProperty(string pstrColName,


Type p_ColType


ref
TypeBuilder r_TypeBuilder)

{


string strFieldName = “m_” + pstrColName;


FieldBuilder field = r_TypeBuilder.DefineField(strFieldName, p_ColType, FieldAttributes.Private);


PropertyBuilder propBldr = r_TypeBuilder.DefineProperty(pstrColName,


PropertyAttributes.HasDefault, p_ColType, new
Type[] { p_ColType });


// The property set and property get methods require a special


// set of attributes.


MethodAttributes getSetAttr = MethodAttributes.Public;


// Define the “get” accessor method for CustomerName.


MethodBuilder getPropMthdBldr = r_TypeBuilder.DefineMethod(“get_” + pstrColName,

getSetAttr, p_ColType, new
Type[] { });


ILGenerator custNameGetIL = getPropMthdBldr.GetILGenerator();

custNameGetIL.Emit(OpCodes.Ldarg_0);

custNameGetIL.Emit(OpCodes.Ldfld, field);

custNameGetIL.Emit(OpCodes.Ret);


// Define the “set” accessor method for CustomerName.


MethodBuilder setPropMthdBldr = r_TypeBuilder.DefineMethod(“set_” + pstrColName,

getSetAttr, null, new
Type[] { p_ColType });


ILGenerator custNameSetIL = setPropMthdBldr.GetILGenerator();

custNameSetIL.Emit(OpCodes.Ldarg_0);

custNameSetIL.Emit(OpCodes.Ldarg_1);

custNameSetIL.Emit(OpCodes.Stfld, field);

custNameSetIL.Emit(OpCodes.Ret);


// Last, we must map the two methods created above to our PropertyBuilder to


// their corresponding behaviors, “get” and “set” respectively.

propBldr.SetGetMethod(getPropMthdBldr);

propBldr.SetSetMethod(setPropMthdBldr);

}

Step 3: Create the Type.

    Assign the created type to a module-level variable e.g. _RowClass because you will need to refer to this everytime you need access to the object.

_RowClass = tb.CreateType();

Step 4: Create the data grid column and bind a data field to it.

You can use this method to create the data grid column. Add the created column to the grid by calling DataGrid.Columns.Add method.

 


private
DataGridBoundColumn CreateDataGridColumn(string pstrHeader,


string pstrBoundColumn,


Type p_DataType,


bool pbIsReadOnly)

{


DataGridBoundColumn col = null;


if (p_DataType == typeof(bool))

{

col = new
DataGridCheckBoxColumn();

}


else

{

col = new
DataGridTextColumn();

}

col.Header = pstrHeader;

col.Binding = new System.Windows.Data.Binding(pstrBoundColumn);

col.Width = DataGridLength.Auto;

col.IsReadOnly = pbIsReadOnly;


return col;

}

Step 5: Populate the collection of data or an array of data.

object[] itemsSource = new
object[<<Number of Rows>>];

You can repeat this part depending on the number of rows you’ll be adding.

 

object row = Activator.CreateInstance(_RowClass);

 


PropertyInfo propRowNumber = _RowClass.GetProperty(<<Field Name>>);

propRowNumber.SetValue(row, Convert.ChangeType(<<Data Value>>, <<Data Type>>, CultureInfo.CurrentCulture), null);

Insert the created row to your collection.

itemsSource[<<Row Index>>] = row;

Step 6: Set the ItemsSource property of the DataGrid.

grid.ItemsSource = itemsSource;

Retrieving Data from the Dynamic Data Object

To retrieve data from the dynamic data object, you can use the same code when setting the value of a row but using the GetValue method instead of the SetValue. The next code snippet shows how to get the value of a field of the selected row in a DataGrid:

protected
void grid_SelectionChanged(object sender, SelectionChangedEventArgs e)

{


if (e.AddedItems.Count > 0)

{


object obj = Activator.CreateInstance(_RowClass);

obj = e.AddedItems[0];

 


PropertyInfo propInfo = _RowClass.GetProperty(<<Field Name>>);


int intRowNumber = (int)propInfo.GetValue(obj, null);

 

}

}

March 3, 2009

By Design, Infragistics’ XamWebMenu Root Items Can’t Have Icons

Filed under: Uncategorized — jojitsoriano @ 3:59 am
Tags: , ,

When I first tried to use XamWebMenu control (Silverlight LOB CTP Feb. 2009 version) for the application menu bar of my Silverlight project, I encountered what I thought was a bug in XamWebMenu. I could assign an image file to the Icon property of the top-level XamWebMenuItem but the image wouldn’t show up. I posted this query to the Infragistics’ forum:

And here’s the reply:

This code works and here’s the output:

About the issue on the VS2008 crashing and exiting when I resize the Preview and xaml windows, I found out by isolating the Xaml tags that this was happening when the XamWebSeparator was included in the Xaml. I haven’t asked Infragistics’ about this but I’ll post it again here when I have an answer.

Blog at WordPress.com.