Friday, November 21, 2008

Silverlight Tips

Question: If the image is larger than its container, it will pass through the border of its container. How can I restrict the size of the image (or other objects)?

Answer:
Clip the object using Canvas.Clip



Question: How do I animate a object to simulate the zoom function?

Answer:
Set the Scale Transform and then use a storyBoard to control the ScaleX and ScaleY.
Remember to put the storyboard inside the Canvas.Resources (Assume you use Canvas here)

Question: How should I make an object disappear?

Answer:
Setting the object's opacity to zero is not a good way.

The following code should be used:
texbox.visibility = Visibility.Colapsed

Other articles you may be interested:

http://msdn.microsoft.com/en-us/library/cc295092.aspx

http://silverlight.net/forums/t/9422.aspx

Friday, November 14, 2008

Sunday, November 9, 2008

LINQ to SQL is DAL?

LINQ to SQL is DAL?
http://forums.asp.net/t/1145876.aspx
http://oakleafblog.blogspot.com/2007/10/avoid-linq-to-sql-data-objects-vs.html
http://blogs.class-a.nl/blogs/anko/archive/2007/11/01/linq-to-sql-is-the-data-access-layer-dal.aspx
http://blogs.vertigo.com/personal/keithc/Blog/archive/2007/06/28/linq-to-sql-and-the-quote-request-scoped-datacontext-quote-pattern.aspx
http://krisvandermotten.wordpress.com/2006/11/19/creating-a-data-access-layer-with-linq-to-sql-part-1/
http://blog.codeville.net/2007/11/29/linq-to-sql-the-multi-tier-story/

Reading and Writing Excel Spreadsheets Using ADO.NET C# DbProviderFactory

This is a good post talking about reading excel spreadsheets using ADO.net. You can read the data using SQL statement easily.

Read Excel Spreadsheet using ADO.NET and DbDataReader
Once you have the connection string all normal ADO.NET coding applies. Here is some sample code that reads each row of the excel worksheet using DbDataReader. You don't have to use the DbProviderFactory Classes. I thought I would show it just for kicks.
string connectionString = @"Provider=Microsoft.Jet. OLEDB.4.0;Data Source=Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
// Cities$ comes from the name of the worksheet
command.CommandText = "SELECT ID,City,State FROM [Cities$]";
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
Debug.WriteLine(dr["ID"].ToString());
}
}
}
}


Reference:
http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx

David Hayden's blog is a great blog that regularly posts ASP.net Data Access article.

Friday, November 7, 2008

ASP.net Beginner - ContentPlaceHolder

This post is for beginner of ASP.net.

ContentPlaceHolder is one of the great feature ASP.net.

When you use a masterpage to make layout of your site. You have to put several ContentPlaceHolder in it so that other pages can put their content in the ContentPlaceHolder. Kindly read the following examples and reference.


1. Place the ContentPlaceHolder in one place (can have default content in ContentPlaceHolder), e.g.

<asp:contentplaceholder id="FlowerText" runat="server"/>

2. And then place the content in other place.

<asp:content id="Content1" contentplaceholderid="FlowerText" runat="server"> Actual content here </asp:content>

References:
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/masterpages/default.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.contentplaceholder.aspx

http://msdn.microsoft.com/en-us/library/fft2ye18(VS.80).aspx

Using Inheritance

References:

http://www.codeproject.com/KB/aspnet/page_templates.aspx

Microsoft learning of ASP.net

http://www.microsoft.com/learning/en/us/syllabi/2311Afinal.mspx

Make use of CSS Rule Objects

Typically, we define CSS in an external stylesheet and then use it.

In previous project, I am required to change the rules defined in CSS dynamically. We normally add or remove rules most of the time and seldom change them. In this case, we should use CSS Rule to deal with it.

CSS Rule Object provide the ability to access and modify rules defined in CSS.

Since IE and Firefox have different implementation, we first look at how to use it:

BrowserUsage
Internet Explorerdocument.styleSheets[0].rules[0]
Firefoxdocument.styleSheets[0].cssRules[0]

Let's modify a CSS Rule to see how powerful it is.
For example, we have one stylesheet imported and the content is shown below:

p{
font-size:10px;
}

You want to change this rule so that content inside tag will be in font-size:12px. Here's the code:

var cssSheet=document.styleSheets[0];
var rule=cssSheet.cssRules? mysheet.cssRules[0]: cssSheet.rules[0]; // check compatibility between IE and Firefox
rule.style.fontSize="12px"; //remember in javascript we have to use fontSize instead

This is all the code and it is very simple. We still have a better solution in this case. It is the use of Javascript Framework. I personally recommend you to use JQuery.

Here is where you can find JQuery:
http://jquery.com/

I'll talk about it later.

Reference:

http://www.javascriptkit.com/dhtmltutors/externalcss3.shtml

Technology Tips

In this blog, I will talk about many common problems and tips I encounter in my work everyday.

I'll also post some my old articles to help new programmers.

Many articles about new technology and products that I am interested in will put here.