Skip to main content


Showing posts from May, 2011

Silverlight Panels: How to use Canvas Layout in Silverlight?

Silverlight Panels: How to use Canvas Layout in Silverlight?In this article let us learn how to use Canvas Layout panelin a Silverlight application. CanvasLayout panelis another most useful panel we ever use in Silverlight. Using this we can place any content any where inside the canvas. Canvas is mostly useful whenever we want place any objects in layered fashion. We can put our content in specific location by providing absolute left and top position to Canvas Layout
As usual, open visual studio and select Silverlight project. We can notice that there is a Grid layout in our MainPage.xaml.  Remove the default Grid layout and just drag and drop the Canvas Layout into our application. The code for this looks like as
<Canvas Name="canvas1"> <Rectangle x:Name="rectFirst" Fill="Blue" Height="100" Width="100" /> <Rectangle x:Name="rectSecond" Fill="red" Height="100" Width="100"/> </C…

“Not able to view the solution file in Visual Studio” – Hide and Show solution file in Visual Studio

Sometime you may came across with this problem that, you are not able to view the solution file in Visual Studio though you have solution file in proper place and the file physically exists in solution folder . You may just wonder why you are not able to view the solution file. Yeah, it could be some missing settings with in visual studio.If you create any Visual Studio Project, by default you will get below view in Solution Explorer ( Solution file and the Project files associated with in solution ).More Detail at Original Source

How do you convert a string into an enum?

How do you convert a string into an enum? it's one of those methods that you can never find when you're looking for it, but once discovered it seems blindingly obvious: object Enum.Parse(System.Type enumType, string value, bool ignoreCase);So you can write the following kind of code: enum Colour { Red, Green, Blue } // ... Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true); Console.WriteLine("Colour Value: {0}", c.ToString()); // Picking an invalid colour throws an ArgumentException. To // avoid this, call Enum.IsDefined() first, as follows: string nonColour = "Polkadot"; if (Enum.IsDefined(typeof(Colour), nonColour)) c = (Colour) Enum.Parse(typeof(Colour), nonColour, true); else MessageBox.Show("Uh oh!");What a time saver - thanks

Windows Phone 7 Tutorials Jump Start with Mango - 2 - Know more about Page

Windows Phone 7 Jump Start with Mango - 2 - Know more about PageIn my previous post, we discussed on how to create a Windows Phone 7 application and what are the different parts of the MainPage.xaml. We also created a small and simple HelloWorld application as the quick start. I guess, now we are comfortable to create a basic application with a good UI (if you already know how to design a XAML page).   It's time to explore more in depth about the page. In this post, we will discuss about the base class called "Page". Read to know more about it.     Introduction to Page Like "MainPage.xaml", every Windows Phone 7 page inherits from "PhoneApplicationPage" by default, which is part of Microsoft.Phone.Controls namspace. PhoneApplicationPage itself derives from the base class called "Page", part of System.Windows.Controls namspace. Every "Page" is nothing but a derived class of UserControl and if you are already familiar with the UserCo…

Windows Phone 7 Jump Start with Mango - 1 - Creating a Hello World Application

Windows Phone 7 Jump Start with Mango - 1 - Creating a Hello World ApplicationRecently thought to take some break from core Silverlight programming and start learning something new. As I will be working on Silverlight in office, hence decided to start exploring Windows Phone 7 in my off time. Though, it is also in Silverlight, but there we can learn something new apart from the actual Silverlight development. Now onwards, I will write about Windows Phone 7 programming and whatever I will explore, will post here in my blog.   Jump started with my first exploration to create a "Hello World" application in Windows Phone 7.1 (Mango) public Beta. This is the first post of the series. As a beginner I will be contributing to the series and if something that I can improve in any of the posts/demos, please let me know by providing your inputs using the Comment box. Hope this series will help the beginners to learn about it.     Prerequisite If you are new to Windows Phone 7, you need…

User interface strings in Cocoa

Introduction (the wrong way)Putting a text string in your user interface is not a difficult thing to do on a technical level. In code, filling in text can be as simple as setting the text property of a UILabel to a literal string: someUserInterfaceLabel.text = @"Text to display";(This code is for an iOS UILabel. On Mac OS X, you would set the stringValue property of anNSTextField but otherwise the step is the same.)While this will work, you should never set a user interface string this way.More at Original Source

Tips & Tricks for conditional iOS3, iOS3.2 and iOS4 code

A project or target that supports multiple versions of iOSTo make an application target that runs on multiple versions of iOS is relatively simple:Set the "Base SDK" in your projects settings to the newest version number of iOS whose features you may want.Set the "iPhone OS Deployment Target" to the oldest version number of iOS that you will supportHowever, getting the target settings correct is the easy part of the problem. The hard part is using new features on newer iOS versions without breaking the app on older versions. Running in the 3.1.3 simulator
Detail at Original Source

A ZoomingViewController to animate a UIView to fullscreen

ZoomingViewController is a class you can attach to any existing view that will let you zoom the view to fullscreen with a single tap, rotate the view while in fullscreen by rotating the device and tap to return to the original inline state. IntroductionThe ZoomingViewController class in this week's sample project handles the zooming in the following sample app: The animation between the inline and fullscreen states is smooth and you can rotate the device in fullscreen to rotate the view.You can attach the ZoomingViewController to any view to add this behavior.Source

Grouping Records in Silverlight DataGrid using PagedCollectionView

Do you work with Silverlight DataGrid and want to group your records inside the DataGrid in a proper manner? If so, this article is for you. Here we will learn about data grouping inside a DataGrid. In this article, we will learn how to group data inside a Grid. We will discuss all these steps-by-step and with proper images, so that, you can understand it very easily. The full source code has been attached. You can freely download it and that will be more helpful for you to understand. Read the complete article to learn it.
Detail here at Original Source

Collection Initializers in .NET

Many of you have used property initializers in your code. Object initializers and property initializers are common operations of every program. But do you know, .NET supports Collection initilization directly for all IEnumerable objects ? In this post lets take a brief introduction of Collection Initializers in .NET.Suppose you want to create an array which holds some values, you might write :string[] myarray = {"Abhishek", "Abhijit", "Atul", "Jaberson" };Oh, it works. myarray is going to initialize with values specified inside the curl braces.You might think, this is very common syntax that we all know from basic programming languages. But yet, C# puts this further, lets demonstrate :List mylst = {1,2,3,4,5};Yes even this works as well. Actually curl braces produces an IEnumerable which you can cast to any custom collection type.You can even use this syntax to do like this :List mylst = { 1, 2, x * 20, this.GetInt(), 44 };The 3rd value will be…

How to store custom objects in web.config ?

In this Post, I am going to discuss about web.config. Normally in our daily life, we used to have some data inappSettings section of web.config and read it when required. That is in string form. But there are lot more than this. We can update the data in web.config programmatically as well .Now another main point is, we can store some object of custom type in web.config as well, which we normally don't do it. But this can be very useful in several scenarios.
Have anyone tried to update some value or add some value in web.config? W'll have brief discussion on this. First, This is very common to have some constant data atappSettings section of web.config and read it whenever required. So how to read this ( for beginners). //The data is stored in web.config as <appSettings> <add key="WelcomeMessage" value="Hello All, Welcome to my Website." /> </appSettings> // To read it string message = ConfigurationManager.AppSettings["WelcomeMess…

Find duplicate with Linq

This small tips discussed about how to get list of duplicate items for the collection that we do in sql.
For example I have to get list of the email id which is get entered in user table more than one time.
[sourcecode language="csharp"]
SELECT email,
COUNT(email) AS NumOccurrences
FROM users
GROUP BY email
HAVING ( COUNT(email) > 1 ) [/sourcecode]
Linq query work same as on the set of collection and which make use of count[sourcecode language="csharp"]
DataClassesDataContext db = new DataClassesDataContext();
var duplicates = db.Users
.GroupBy(i => i.emailid)
.Where(g => g.Count() > 1)
.Select(g => g.emailid);
foreach (var d in duplicates)
[/sourcecode] So by using above query you can easily achieve task of finding duplicate for your set of collection.

How to Sort Generic List Using Lambda Expression For Dynamic Type And Dynamic Property ?

eneric enough to sort any type of collection and also the property based on which it has to be sorted will be dynamic.This is very much easy to hit this requirement using Lamda Expression. Below code will do this for you. [sourcecode language="csharp"]
public class Utility
/// <Summary>
/// Gets the sorted list.
/// </Summary>
/// <param name="source" />The source.
/// <param name="sortColumn" />The sort column.
/// <param name="sortDirection" />The sort direction.
/// <The sorted list. />
private List GetSortedList(List source, string sortColumn, SortDirection sortDirection)
// Prepare the dynamic sort expression
var paramExp = Expression.Parameter(typeof(T), typeof(T).ToString());
Expression propConvExp =
Expression.Convert(Expression.Property(paramExp, sortColumn), typeof(object));
var sortExp = Expression.Lambda>(propConvExp, paramExp); if (sortDirection == SortDirection.Ascending)
return source.AsQuerya…

LINQ and Nullable Values or SQL ISNULL with LINQ

In this tips I am going to show how you can deal with the Nullable values in LINQ queries and how you can achieve functionality like SQL ISNULL function. Let's put it as a problem statement I am dealing with the LINQ queries, In which I have to diplay "N/A" were the value is null for the given property/column. Now you can have multiple solution to do thatSolution 1 You can use ternary operator as shwon in below example. HereMobileNo = "N/A" for the null values
[sourcecode language="csharp"]
var user = from u in Users
join uc in UserClients on u.Id equals uc.UserId
into myuserwithclient
from m in myuserwithclient.DefaultIfEmpty()
select new {
MobileNo = (m.MobileNo == null) ? "N/A" : m.MobileNo
[/sourcecode]Solution 2 Use special Coalescing operator (??) as showin in below example. Here MobileNo = "N/A" for the null values
[sourcecode language="csharp"]

Multiple Sort For Collection Using LINQ

There are quite a lot of instance where you need to do a primary sort and you need a secondary sort on the same collection and sometimes even multiple sort. With LINQ we can achieve it pretty straight forward. Let us assume the situation here. We have a list of employees and we need the output to be sorted by city and within every city, we need it to be sorted by the employee's first name. Below is the code which will get your job done.[sourcecode language="csharp"]
employeeList.OrderBy(item => item.FirstName).OrderBy(item => item.City);
[/sourcecode] Remember the inner sort / secondary sort has to appear first and the outer sort at the last.Detail...

How To Translate Text With Google Translate and JSON on the iPhone

Google Translate provides a really neat API that you can use to quickly and easily use in your apps to translate text between tons of different languages. In this tutorial, we're going to show you how you can use this API from your iPhone app to translate text a user enters in, back and forth from Japanese to English, until a "final match" is found, similar to the amusing Translation Party web page created by Will Carlough and Richard Boenigk.More Detail .. 

Generating simple collections for Pivot Viewer

The Silverlight PivotViewer control is an easy way to have a fast and spectacular gallery for your website/webapp. In this article I'll show how to generate collections for the PivotViewer using Linq-to-Xml and the command line tool.PivotViewer IntroductionThe control enables filtering, sorting with fluid animations, and uses Deep Zoom technology to make the loading fast. To get an idea about it, check out the ...More at Original Source

Silverlight 5 Features Ancestor Relative Source Binding

Silverlight 5 Features Ancestor Relative Source BindingSilverlight 5 has another new feature called Ancestor Relative source binding. It was already available in WPF and has been newly introduced in Silverlight 5 beta. Using this, you can now bind to the relative ancestor elements very easily.   Let's discuss it with a small example where we will create a Control Template for a Button and bind it's Tag property to the actual element to display text, instead of setting the Content property. Read to know more.     Let us create a simple basic style for a button. For our example, we will not use any visually stunned button style. So, our button will just look like a TextBlock. Let's create the style with a TextBlock control as shown below:   <Style x:Key="ButtonStyle" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> ...
Read more at: Original Source