.NET 3.5: Introduction to XAML – Part 1

What is XAML

So what is XAML anyways?  It stands for eXtensible Application Markup Language and is based on XML.  It was initially created to be used in WPF (Windows Presentation Foundation) but is now being used also in WF (Windows Workflow Foundation), Silverlight, and XPS (XML Paper Specification). 

Why XAML

So why another markup language?  The reason behind creating this to be used in WPF is to allow the designers (those responsible for the graphical user interface) and developers (those who code the behavior)  to collaborate well, to have them work on their stuff separately, and once done merge their stuff without a hitch.  End result is a top notched graphical user interface and a perfectly working application.

 

XAML Tools

The major tools for creating XAML are: Expression Design, Expression Blend, and Visual Studio (starting from version 2008).  As a developer, you can actually just use Visual Studio to create your visual elements in XAML and code-behind it.  But for more complex graphics, the two Expression products are more suitable.

 

XAML in WPF

Since XAML is a declarative language, it is used to describe objects in .NET, just like what HTML is used to describe what should be displayed on a Web page.  XAML describes objects form a subset of .NET namespaces, which include System.Windows, System.Windows.Controls, System.Windows.Data, and System.Windows.Media

Since XAML is XML based, it can be used to represent a tree of objects.  And as with all XML markups, XAML is case sensitive.

XAML in WPF uses WPF namespace (the same namespace concept used in XML) to avoid confusion with XAML used in WF, and so on.

XAML is compiled, at runtime, into BAML (Binary Application Markup Language), a more optimized form for parsing, and embedded as a resource in EXE or DLL.

A sample XAML listed below describes a button object.  It will display a Button control on a StackPanel layout on the UI with default visual presentation and default behaviors.

<StackPanel>
  <Button Content="Click Me"/>
</StackPanel>

Other sample XAMLs:

<Button Background="Blue" Foreground="Red" Content="This is a button"/>
<Button>
  <Button.Background>
    <SolidColorBrush Color="Blue"/>
  </Button.Background>
  <Button.Foreground>
    <SolidColorBrush Color="Red"/>
  </Button.Foreground>
  <Button.Content>
    This is a button
  </Button.Content>
</Button>

If you are coming form an ASP.NET or Web background, these XAML samples do look familiar.  Stylesheets is what comes into my mind though.

Advertisements

SQL Server 2005: SELECT, INSERT, UPDATE, DELETE

The parts of a SELECT statement are:

SELECT 
FROM 
WHERE 
GROUP BY 
HAVING 
ORDER BY 
FOR XML
OPTION

By default, ALL is assumed in SELECT, thus including every row.  Using SELECT DISTINCT excludes duplicate rows.  Note that you can also use DISTINCT in aggregate functions, like below:

SELECT COUNT (DISTINCT Column)
FROM Table

You can use ORDER BY on any column on the table even if it is not returned or not part of the SELECT list.  The FOR XML clause is used for outputting XML data while the OPTION clause is for making query hints.

 

The INSERT statement can take either of the two following forms:

INSERT INTO Table (Column1, Column2)
VALUES (Value1, Value2)

INSERT INTO Table (Column1, Column2)
SELECT ...

Note that the column list are optional on both forms.

 

The parts of an UPDATE statement are:

UPDATE
SET
FROM
WHERE

An UPDATE can be created from multiple tables but only one table is affected, meaning only one table can be the subject of an update action.

 

The DELETE statement has the shortest syntax.  Just provide the table name and optionally a WHERE clause.

SQL Server 2005: Interview Q&A

I recently had a technical interview and the following questions gave me a  hard time:

  • How many non-clustered indexes can you have?  I know you can only have 1 clustered index but I have no idea for the non-clustered.  The answer is 249.  But in SQL Server 2008, this number was increased to 999.
  • Which among the 2 key constraints allow you to have a NULL value, PRIMARY KEY or UNIQUE?  I know primary keys should not be null, and I am right.  The UNIQUE constraint will allow you to add only one NULL value and more than that will be considered as duplicate.
  • How do you add a DEFAULT constraint in an existing table using SQL?  You could easily do this on the SQL Server Management Studio, but since it’s asking for the SQL, it should look like the following:
    ALTER TABLE MyTable 
      ADD CONSTRAINT MyConstraint 
        DEFAULT 'MyDefault' FOR MyColumn
    
  • What are the T-SQL statements used for transactions?  These should be BEGIN TRAN, COMMIT TRAN, ROLLBACK TRAN, and SAVE TRAN.  The SAVE TRAN is like a bookmark or a save point.  You can roll back to a save point.
  • What is a RANK() function?  This one I have never used.  It is a built-in function in T-SQL under the Ranking Functions category.  For more information, click here.
  • What is a ROLLUP operator?  Again I have never used this.  It is used to summarize data.  I probably will have to get familiar with this since I do lots of reporting.  It might make my SQL statements shorter.  For more information, click here.

General: I’m back blogging again :)

These past 2 years have been busy for me, with a new job and a new baby in 2009.  Unfortunately I left my job to take a family-related sabbatical for 8 months.   Now I am looking for another job and blogging again.

Since my last blog on the following technologies: .NET Framework 2.0 and briefly on 3.5 (should probably look at 3.0 first), Visual Basic 2005, SQL Server 2005, and ASP.NET 2.0, newer versions have appeared.  We now have .NET Framework 4.0, Visual Basic 2010 (previous to that Visual Basic 2008), SQL Server 2008 and ASP.NET 4.0 (previous to that ASP.NET 3.5 and 3.0).

I will try to touch briefly on these new versions and take a look what is new there while still focusing on the older versions.

I also plan on putting up a portfolio of my work that I did as an independent contractor, showcasing my work on desktop, web, and mobile applications.