WPF Tutorial – Part 1 : WPF DataBinding

July 7th, 2010 admin No comments

Nowadays everyone running behind WCF and WPF. I have come across many articles related to these topics while googling. I hope you too have read lot of articles on these topics. But here am not going to bore you with definitions and keywords. According to me,learning by example is always a good way of learning new things, that’s why am going to expose the knowledge i have acquired via examples. In this article, will provide some practical examples which reviews some important features of Windows Presentation Foundation. It covers the following features :

  • WPF DataBinding
  • WPF Styles and Control Templates
  • WPF Commands and Custom WPF Commands
  • WPF Dispatcher
  • WPF Resources, Layouts
  • WPF CLR properties and Dependency Properties

These will done in a series of articles, one at a time.

This article is the first in a series, the entire series barely scratches the surface of the immense WPF platform, and it does not dive too deeply into core level on any specific topic. The purpose of this series is to familiarize the reader with the basic WPF programming model.

WPF DataBinding Example: Display a set of data in ListView.

DataBinding.xaml :

<Window x:Class=”DataBinding.DataBinding”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
Title=”DataBinding example” Height=”300″ Width=”300″>
<Window.Resources>
<Style x:Key=”TextBlockStyle” TargetType=”{x:Type TextBlock}”>
<Setter Property=”Foreground” Value=”Black” />
</Style>
<Style x:Key=”GridHeaderStyle” TargetType=”{x:Type GridViewColumnHeader}”>
<Setter Property=”Foreground” Value=”#356CAD” />
<Setter Property=”FontSize” Value=”12pt” />
</Style>
</Window.Resources>
<Grid>
<ListView x:Name=”ItemsListView”>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumnHeader Content=”Item Name”  Style=”{StaticResource GridHeaderStyle}” />
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding Name}”  Style=”{StaticResource TextBlockStyle}”></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn>
<GridViewColumnHeader Content=”Item Rate”  Style=”{StaticResource GridHeaderStyle}”/>
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding Rate}”></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>

DataBinding.xaml.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace DataBinding
{
///
/// Interaction logic for Window1.xaml
///
public partial class DataBinding : Window
{
public DataBinding()
{
InitializeComponent();

ObservableCollection oList = new ObservableCollection();
oList.Add(new Items{ Name=”Ram”, Rate=”23.8″});
oList.Add(new Items { Name = “Mother Board”, Rate = “10303.56″ });
oList.Add(new Items { Name = “SMPS”, Rate = “3421.4″ });
oList.Add(new Items { Name = “KeyBoard”, Rate = “200.0″ });
oList.Add(new Items { Name = “Monitor”, Rate = “3421.4″ });
CollectionViewSource dataSource = new CollectionViewSource { Source=oList };
ItemsListView.ItemsSource = dataSource.View;
}
}
}

item.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataBinding
{
class Items
{
public string Name { get; set; }

public string Rate { get; set; }
}
}

Download Source : Wpf-DataBinding-Example – 1

We are back…

June 25th, 2010 admin 1 comment

Hi everybody…

We are back after short break. Will be posting more articles…Keep visting the site.

Categories: Misc Tags:

Apple's Response to Windows 7 Release

November 3rd, 2009 admin No comments

Microsoft released Windows 7 on last week. And here is the video ad response from APPLE.


Comics – November

November 3rd, 2009 admin No comments

Understanding JSON

October 29th, 2009 admin No comments

Today, i come across some good articles on JSON. And here is the link where JSON is explained so well.  Also you can find some good collection of related links…

SQL SERVER – Rules for Optimizining Any Query – Best Practices for Query Optimization

October 29th, 2009 admin No comments

Best Practices for Query Optimization

  • Table should have primary key
  • Table should have minimum of one clustered index
  • Table should have appropriate amount of non-clustered index
  • Non-clustered index should be created on columns of table based on query which is running
  • Following priority order should be followed when any index is created a) WHERE clause, b) JOIN clause, c) ORDER BY  clause,  d)  SELECT clause
  • Do not to use Views or replace views with original source table
  • Triggers should not be used if possible, incorporate the logic of trigger in stored procedure
  • Remove any adhoc queries and use Stored Procedure instead
  • Check if there is atleast 30% HHD is empty – it improves the performance a bit
  • If possible move the logic of UDF to SP as well
  • Remove * from SELECT and use columns which are only necessary in code
  • Remove any unnecessary joins from table
  • If there is cursor used in query, see if there is any other way to avoid the usage of this (either by SELECT … INTO or INSERT … INTO,     etc)

Source : SqlAuthority

Google Makes Your Search More Musical!

October 29th, 2009 admin No comments

Google has entered the online music market to allow US consumers to search using song titles, artists or snippets of lyrics.

The top search engine has said the service will offer an alternative to the illegal file-sharing which record companied have been trying to stop.The Google music offering will also spring up in peer-to-peer file searches, meaning people will be able to decide on an alternative to pirated music.

According to Google, the words “music” and “lyrics” are among the top 10 search terms in its web statistics.The company will now find partners in other countries to allow international consumers to use the service.

“This feature doesn’t just make search better. It also helps people discover new sources of licensed music online while helping artists to discover new generations of fans and reconnect with longtime listeners,” Google said in a statement.

Google has made available a video preview of its music search feature which is viewable below.

The music features will not be available to users elsewhere in the world. But Google is open to talking with possible overseas partners, said Marissa Mayer, vice president of search product and user experience at Google.

“This is pushing search traffic and business opportunities downstream to online partners and artists and labels, so we’re happy to provide a great music experience and also direct lots of music-seeking traffic to partners that can take it from there and convert it to great music discovery,” said R.J. Pittman, product manager for the music service at Google.

Windows 7

October 27th, 2009 admin 2 comments

Windows 7 is finally released into the wild!  So far the operating system has received great reviews around the web. Amazon even said that Windows 7 is bigger than Harry Potter, so things are looking bright for them .

Many say that Windows 7 is what Windows Vista should have been, an optimized operating system that combines the looks of today with interesting new features and less bloat.

Here are the things that I personally like in Windows 7:

* Automatic digital camera (and other devices) recognition with proper actions displayed (e.g. copy photos from digital camera to the               computer system). No driver installation or third party software needed to do that.
* The operating system feels more responsive and seems to run better on low-end hardware than Vista
* Better troubleshooting options
* The new taskbar. It takes a while to get used to the new features but they are very handy (e.g. pinning software to the taskbar)                    once you get used to them
* Light theme customizations without system file patching
* Search Connectors to search the Internet from within Windows Explorer
* Better 64-bit support (meaning developers who want a certificate need to provide 32-bit and 64-bit editions of their programs)
* Home Group feature for easier home network management and creation

Also Check Windows 7 Blog

Snip from the PCMAG:

Microsoft’s decision to leave Windows XP users behind, with no easy upgrade path to Windows 7, is, possibly, the sole mistake of an otherwise pitch-perfect product development and launch campaign.

Yes, I know there’s precedent for Microsoft not helping customers upgrade from multi-generations-old operating systems. When XP shipped in October of 2001, Windows 3.1 and even Windows 95 were left behind. The exact phrasing Microsoft uses in its literature is: “No Supported Upgrade Paths.” When Vista shipped in January 2007, XP had multiple paths, but Windows 2000 (and older OSs) were left out in the cold. more..

Have you already installed W7 on your computer? Let me know what you think in the comment section!

Visual Studio 2010 and ASP.NET 4.0 beta 1 Released

August 12th, 2009 admin No comments

Microsoft has released Visual Studio 2010 and ASP.NET 4.0 beta 1recently, I felt there are some amazing features which can help developer improve productivity.

Visual Studio 2010 and .NET Framework 4 focuses on the core pillars of developer experience, support for the latest platforms, targeted experiences for specific application types, and core architecture improvements.

Check out the following links:

What’s New in Visual Studio 2010

What’s New in the .NET Framework 4

Download Visual Studio 2010 and .NET Framework 4 Beta 1

Bulk Insert – SQL Server

August 12th, 2009 admin 6 comments


Sample:
CREATE  PROCEDURE InsertEmployees
/* ———————————————————-
Parameters
In :
@strXML = contains employee list as XML
Example:   ‘<root>
<emp EmpName=”Srinath” EmpSalary=”10000″ />
<emp EmpName=”sree” EmpSalary=”15000″ />
</root>’
———————————————————- */
@strXML varchar(8000)
AS

Declare @intPointer int

exec sp_xml_preparedocument @intPointer output, @strXML

INSERT into employee

SELECT  EmpName, EmpSalary

FROM OpenXml(@intPointer,’/root/emp’,2)

WITH EmpName varchar(20) ‘@EmpName’ , EmpSalary varchar(20) ‘@EmpSalary’)

exec sp_xml_removedocument @intPointer

———————–

EXEC InsertEmployees ‘<root><emp EmpName=”Srinath” EmpSalary=”10000″ /><emp EmpName=”sree” EmpSalary=”15000″ /></root>’

sp_xml_preparedocument

Reads the XML text provided as input, parses the text by using the MSXML parser (Msxmlsql.dll), and provides the parsed document in a state ready for consumption. This parsed document is a tree representation of the various nodes in the XML document: elements, attributes, text, comments, and so on.

sp_xml_preparedocument returns a handle that can be used to access the newly created internal representation of the XML document. This handle is valid for the duration of the session or until the handle is invalidated by executing sp_xml_removedocument.

OPENXML

OPENXML provides a rowset view over an XML document. Because OPENXML is a rowset provider, OPENXML can be used in Transact-SQL statements in which rowset providers such as a table, view, or the OPENROWSET function can appear.

Sample:

OpenXml(@intPointer,’/root/emp’,2)

WITH EmpName varchar(20) ‘@EmpName’ , EmpSalary varchar(20) ‘@EmpSalary’)

sp_xml_removedocument

Removes the internal representation of the XML document specified bythe document handle and invalidates the document handle. To avoidrunning out of memory, will run sp_xml_removedocument to free up thememory.