Monday, May 24, 2010

Silverlight Datagrid pager issues and PageCollectionView wrapper

Tried Datagrid pager by

<data:DataPager x:Name="TempDataGridPager"
               Source="{Binding Path=Source,ElementName=DataGrid1}"
                   PageSize="2" >
           </data:DataPager>

and then

DataGrid1.ItemsSource = ListPictures;

It did not work. Then looked at the following article

DataPager Class 

had to use PagedCollectionView, which provides paging functionality .to make it work

PagedCollectionView itemListView = new PagedCollectionView(ListPictures);
            TempDataGridPager.Source = itemListView;
               DataGrid1.ItemsSource = itemListView;

Wednesday, May 19, 2010

Silverlight InitializeError- Invalid or malformed application: Check manifest Changing Namespace

I recently changed the namespace in a Silverlight project and ran into lot of problems! Visual Studio was smart to change the namespace in many files, but I ran into this bug and the page will not render

InitializeError- Invalid or malformed application: Check manifest.

I researched this and came across this forum posting:

InitializeError- Invalid or malformed application: Check manifest

First I learnt an easy way to  look at the XAP file. Just change the extension to .zip and you can unzip it and look in the App.Manifest file. No problem there. Then going through the thread I found the solution as recommended by R. Wiltschek. Quoting him

“In human-readable words, this is what fixed it for me: 1. Open the properties of your project. 2. On the first page, open the drop down list of "Startup object". 3. Select the page your project starts with. In my case, changing the name of the namespace broke the startup object.”

It worked for me!

Dynamic C#, Visual Studio 2010, OData

Attended a talk by Kevin Pilch-Bisson and Ryan Dawson on

Sneak peak at the new language features of .Net 4.0 and VS2010.

Very good demo by Kevin on using the dynamic C# features to interface to Office Word and Excel without going through lot of COM idiosyncrasies, and Javascript interface which enables you to use C# classes.

Ryan talked about IronPython and IronRuby which looks interesting.

Attended an all day OData event by Douglas Purdy and Jonathan Carter. The presentation was similar to the one in MIX10. Exciting technology, might be useful for XBRL data presentation.

Tuesday, May 11, 2010

Silverlight controls with custom shapes

In Silverlight and WPF you can do  amazing things with the controls. You can make controls take different looking shapes.  Scott Guthrie has an excellent blog Silverlight Tutorial Part 7: Using Control Templates to Customize a Control's Look and Feel describing how this is done. This  is one of the controls he shows. A calendar inside a button!

step115

blah!bLaH!BLOG!! (funny name!) has couple of blogs

  1. WPF: A ControlTemplate for an Analog Clock
  2. WPF: The ItemsPanelTemplate - controlling how ListBox/ComboBox etc. render their children,

The second one shows how to  create an international clock which looks like this. Amazing!

63654627jm7

Jit Ghosh has an excellent blog explaining how to build custom controls.

WPF Control Templates - An Overview.

Jit also mentioned the XAMLPAD editor, which I researched and tracked to Lester’s WPF blog

XamlPadX v2.

Monday, May 10, 2010

Silverlight Animation, Zoom,Perspective Transform, 3D effects

Very interesting effects with Sivlerlight.
Silverlight Sample Browser has excellent examples. Many of them also have source code. I like the following samples from there. Some of the samples require Silverlight 4:

Nikolay Raychev has an excellent demo Perspective 3D in Silverlight 3. The picture of Acanthoscurria_geniculata is awesome!

Silverlight 3's New Perspective Transform by Jeff Prosise is a good introduction to the Perspective Transform.

Mousewheel Zooms in Silverlight 2.0 by Jeff Prosise gives a very good mouse zooming effect animation. This explains the HtmlWindow class! Mouse wheel working with Deep Zoom  is allso a good introduction to HtmlWindow class! Image Effects with Silverlight: Creating the Saturation Light Sample is dramatic!

 Coordinate Systems, Transformations and Units is an excellent reference.

Hardrock Memorabilia is a very good example of Deep Zoom.

Jeff Prosise has an excellent article A Touch of Silverlight which refers to Mycomix which is a very good demo. Click on Thumbnails to see the fun page and then click on any of the Comix icons to get  a new window. Use the mouse to rotate the image and enjoy!

Thursday, May 6, 2010

Silverlight Visual Studio how to add existing Silverlight projects

When you want to use existing Silverlight projects (like demos from Devexpress Silverlight AgGrid) in Visual Studio do the following:

  1. Start a Silverlight Application
  2. Host it in a new web site.
  3. Add the Silverlight Project.
  4. Right click on Web application
  5. Select Properties.
  6. Select Silverlight Applications tab
  7. Press the Add button
  8. Use existing project radio button will be normally selected.
  9. The drop down menu will show you the Silverlight projects available in the solution.
  10. Select add a test page.
  11. Leave the destination folder as ClientBin
  12. Press the Add button.
  13. A test page is added
  14. The XAP file from the silver light project is added to the ClientBin.
  15. Every time you make changes in the silver light project and compile the solution is updated.
  16. Sometime the F5 (Compile and Run) button in Visual Studio does not use the updated file.
  17. You may have to do a compile first and then run it.

Wednesday, May 5, 2010

WCF, Silverlight , Ajax development with Visual Studio

Visual studio offers 2 templates for adding WCF.
The following quote from WCF Visual Studio Templates explains the 2 types:

“AJAX enabled WCF Service Item Template
This template exposes an AJAX control as a WCF service. For more information on AJAX controls, see the AJAX control documentation.

Silverlight-enabled WCF Service Item Template
This template creates a Web service that provides data to a Silverlight client or front-end. The template can be added to a Web site or Web application project to create a WCF service, which includes service code and configuration that support communicating with a Silverlight client. You can then use Add Service Reference to add a client proxy of the service to the client, and exchange data between the Silverlight client and the Silverlight-enabled WCF service.

To access this template, right-click a Web site or Web application project in Solution Explorer, click Add a new item, and click Silverlight-enabled WCF Service.

Visual Basic Note: 
The Silverlight-enabled WCF Service exposes a basicHttpBinding endpoint without enabling any security settings. Therefore, information about the service can be obtained by all clients that connect to this service. Messages exchanged between the service and the client are also not signed or encrypted. To secure the endpoint properly, you should use ASP.NET authentication, HTTPS or other mechanisms. “

Schleichermann has an excellent blog on this topic:  .Net: Difference Between WCF Service and Silverlight-Enabled WCF Service

Muhammad Adnan Amanullah also has an interesting article on this topic:  Ajax enabled web service where he describes how to Make Script based web service which could be called by JavaScript.

Tuesday, May 4, 2010

Sivlerlight Colors Lack of ColorTranslator

System.Windows.Media used for colors by Silverlight  does not have ColorTranslator which would be convenient to specify a color using ColorTranslator.FromHtml(“AliceBlue”).

Colors like AliceBlue is  available in XAML but not in code behind where you have to use Color.FromArgb Method or the following code mentioned in Color Structure

String xamlString = "<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Background=\"MistyRose\"/>";



Canvas c = (Canvas) System.Windows.Markup.XamlReader.Load(xamlString);



SolidColorBrush mistyRoseBrush = (SolidColorBrush) c.Background;



Color mistyRose = mistyRoseBrush.Color;




Laurent Duveau has an interesting solution to this problem in this blog Silverlight – Get Color from Hex



where he shows how to get ColorTranslator with Hex values!

Monday, May 3, 2010

SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used error in Azure, Visual Studio

I copied one of the Azure solutions Thumbs_E1(which was working)  to Thumbs_E1_SL1 folder  along with the project folders to a new folder. Changed all folder names to correspond with the new extension I had.

Thumbnails_E1_WorkerRole to Thumbnails_E1__SL1_WorkerRole
Thumbnails_E1_WebRole to Thumbnails_E1__SL1_WebRole
Thumbnails_E1 to Thumbnails_E1_SL1

When I opened the solution it complained about the projects not being there. I removed the projects folder icons and added the projects again from the renamed folders.

It compiled fine, but would not run and gave me an error

System.InvalidOperationException: SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used.

I found a solution in the following link

Using the CloudStorageAccount.FromConfigurationSetting

Set the Thumbnails_E1 as the start up project and it worked!

Editing code in Blogger, Blogspot Using Windows Live Writer and Code Snippet Plug in

My blogs refer to code. I found the following post which pointed me to the right direction.
Posting Source Code in Blogger from Please Make A Note
I downloaded
Windows Live Writer which has ways to directly write the for blogger and publish it.
In addition, I downloaded the code snippet plug in
Code Snippet plugin for Windows Live Writer by Leo
It works like a charm. Only problem is it produces extra spaces between lines! XAML code requires that you select the HTML option in Code Snippet plug in. This produces good colored source code output. Please make sure to disable line numbering which will make it easy for someone to cut and paste your code!
You also also add labels which is called as categories in Windows Live Writer.
I wanted to add an image. The Live Writer asked me to go to Picasa. I added the image in the Blogger editor!

Silverlight Datgrid control customization

This is a very good introduction to customization in Silverlight datagrid customization by Martin Mihaylov.
Basic customizations of the DataGrid.
Another interesting article is from Scott Morrison
Defining Silverlight DataGrid Columns at Runtime
The template information is put in the App.XAML file as a resource and then used by the Datagrid as a StaticResource. Example given below will color alternating rows with Bisque and NavajoWhite colors :
in App.Xaml file
<Application.Resources>
<Style x:Key="DataGridStyle"  TargetType="data:DataGrid">
<Setter Property="RowBackground" Value="Bisque" />
<Setter Property="AlternatingRowBackground" Value="NavajoWhite"/>
</Style>
</Application.Resources>
and in the Main.Xaml file
<data:DataGrid x:Name="DataGrid1" AutoGenerateColumns="False" Style="{StaticResource DataGridStyle}" >
Another web site which has an excellent color chart is
Web colors from Wikipedia.
This is a very trivial example but can be extended to various parts of the Datagrid for special effects including animation.
For example this header effect

will be produced by the code given below.
App.XAML
<Style x:Key="ImageHeaderStyle" TargetType="prim:DataGridColumnHeader" >
<Setter Property="Foreground" Value="Black" />
<Setter Property="Template"  >
<Setter.Value >
<ControlTemplate TargetType="prim:DataGridColumnHeader"   >
<Canvas Width="100" Height="34" Background="BurlyWood">
<Border BorderThickness="5" BorderBrush="Black"
VerticalAlignment="Center"   >
<TextBlock Width="90" Height="24"  
Text="{TemplateBinding Content}" 
FontSize="16"  Foreground="Black" 
TextAlignment="Center
>
 
</TextBlock>
</Border>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>