Wednesday 10 December 2008

Silverlight Toolkit - Merry Christmas!!

Go grab the silverlight toolkit from here. A newer version got released today. If you are wondering what's new,

Here, take a sneak peek

What's New?

  • More than 80 improvements and bug fixes
  • AutoCompleteBox and NumericUpDown have been moved into the Stable Quality Band.
  • Three new themes have been added: Bureau Black, Bureau Blue and Whistler Blue.
  • The sample application has been given a make-over and is now more polished and easier to navigate.
  • More tests added.
  • Better design-time support in both Visual Studio 2008 and Expression Blend, including icons, property tooltips and better property organization in the property editor.
  • AutomationPeer support added for AutoCompleteBox, Expander and NumericUpDown (as well as UpDownBase).
  • Charting improvements galore!

What's in the Silverlight Toolkit December 2008 release?

Some Links

Silverlight Tookit Quick View

Monday 8 December 2008

Motherjane - All set to create vibes from the fields of sound!!

_DSC7426_Edit

Motherjane a band from cochin (if i'm right) are a bunch of highly talented creative musicians. These guys are true artists.. Their sound is unique, lively, original and backed by good lyrics. I've been a fan since early 2002. I distinctly remember my first experience listening to 'Mindstreet' from a GIR CD (Thanks to montry) It surely did wow! me and since then i have huge respect for this amazingly talented band and boy they deserve some respect!. See the videos below. (i only wished that they managed to make a good video. It's noticeably a bit patchy, not polished well. It's a shame that such talented bands do not get noticed by creative media guys.) I guess we need to spread the word and so here i am doing exactly that..Their's nothing that comes close to describing their sound. All i can say is, the band has certainly taken huge influences from carnatic music and you can definetly hear that vibeing out of Baiju's guitar and eventally the band itself. The sound is unsurpassed, unmatched and totally phenomenal. To me they are inarguably the 'Indian' Dream Theater.

One of the most amazing things about both the music videos from ‘Maktub’ is that one was shot in 25 minutes (”Fields of Sound”) and one in 15 minutes (”Chasing the Sun”).

Maktub - Motherjane Promo

Fields of sound..

Long before religion, music is probably the first spiritual experience anyone is initiated into and this song is a celebration of the knowledge that our souls have been sung to..

Fields of Sound on youtube

Chasing the sun

"Time is the actual distance between people when ones chasing the sun". Brilliant Song!

The band's front man suraj speaks to split magazine on their experience with chasing the sun

"We, being a positive bunch, just enjoyed the trip. Twenty to thirty hairpin curves at an indecent speed took a lot of that joy out of us. As we reached, the sun was well on its way down and the place was closed to the public. It took a precious 25 minutes to find a cop who finally removed the barrier and let us in. Once again the shoot was on. We removed John’s drums and sped down a hill looking for a horizontal surface. We didn’t even have time to think about whether the sun would go down before we set up shop. Actually, I guess all of us did, in the back of our minds. The crew got one camera positioned and we played the song the first time. The sun was sinking. We relocated the camera and took shot number two. The sun was really on its way out. Like a friend of mine in the advertising world said, we all think there’s a lot of time in a day until a shoot happens.

The third time, the camera moved as a handheld. I still don’t know how much of that footage was usable and the only thing in our control was to enjoy the take. We did just that, standing on that beautiful mountain and looking over at the space that expanded before us and giving it all that we had as the sun made its final descent.

In retrospect, I can make the remark that we were ‘chasing the sun’ in every sense during the shooting of its video. "

 

All time favourite - 'Mindstreet'

Mmm, I take a step
in my sleep,
The id lies bleeding in mindstreet.
My angel's shot, full of holes
But now I know how to get him home.
In this world,
made of myth,
The rules change with every beat.
There's magic
in the air,
'Cos here the gods hear your prayer.
Come act your dream in mindstreet,
Do what you want, go where you please,
Kick the devil in his B's
Stop living on your bleeding knees
Will... not give up, they say,
This is the way to Serendip.
Close your eyes,
learn to breathe,
The oceans are just a few thoughts deep.
Believe me...Not in me,
The messenger is rarely worth it.
If you wanna trip, go inside
Where the secrets of the universe hide.
And this is how, it's meant to be
The journey is the way you pay the fee.
Come act your dream in mindstreet.
Do what you want, go where you please.
Kick the devil in his B's
You don't have to live on your knees.
Keep coming back, oh yeah
Human kind has always sensed his track.
Feels better everytime,
To know, that we are all divine

Saturday 6 December 2008

Ideas from IBM - You've got (TOO MUCH) mail..

This white paper can be found here. It talks about efficient ways of handling information overload. The other interesting aspect to look out for is the IORG (Information Overload Research Group) which consists of people from IBM, Microsoft, Intel and various academia. :-|

Schneier on Mumbai

Schneier talks about security w.r.t the Mumbai attacks.

http://www.schneier.com/blog/archives/2008/12/lessons_from_mu.html

Thursday 4 December 2008

jQuery Basics

I’m going to demonstrate a few basic jQuery stuff that you should know before delving into jQuery. If you are new to Javascript you need to be starting here[link]. This might help[link] too. The audience for this tutor are ideally JavaScript novices who want to make a start with jQuery.Let’s start by understanding this small example -


the window.onload() event.




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Basics</title>
</head>
<body>
<script type="text/javascript">
window.onload = function(){ alert("Hello JavaScript!, document Loaded."); }
</script>
</body>
</html>



Now, As you are already aware, the window.onload event is fired when the HTML window loads. In the above code, look at the Javascript, on window.onload() event, we are calling a function, which alert’s the text “Hello Javascript!, document Loaded.”. This code usually runs smoothly unless for instance, if you are loading a lot of images, Then Javascript code isn’t run until all images have finished loaded, including banner ads etc.


Now, We have an interesting problem, In your window.onload() event, if you want to manipulate your document,( which is essentially the HTML DOM (document object model) ), then your document hasn’t loaded yet and your Javascript might not work correctly.


In order to over come this problem, jQuery gives you a basic construct the - ready event which looks like



$(document).ready(function(){
//Your Javascript code here..
});



Let’s now quickly try an example,



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Basics</title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(document).ready(function(){
alert("document has loaded, you can execute your js here..!");
});
});
</script>
</body>
</html>



First thing to note is that above example links to Google’s CDN to load the jQuery core file. You can download the latest version of this file from the jQuery website.Here, the alert statement is guaranteed to work only after the document has finished loading.


jQuery CSS example



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Basics</title>
<style>
label.test {font-weight: bold;}
</style>
</head>
<body>
<label>This is a label</label>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("label").addClass("test");
});
</script>
</body>
</html>



Here, we use the .addClass method to the label element to add a css class. Notice that this code is placed inside the $(document).ready(function(){}); To remove the class ‘test’ for the label element, replace the addClass(“"test”) with the removeClass(“test”);

jQuery Effects example



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Basics</title>
</head>
<body>
<labe>This is a label</label>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("label").click(function(){
$(this).hide("slow");
});
});
</script>
</body>
</html>

Click on the label and notice that it slows disappears.




jQuery Callback example


The syntax for executing a callback with no arguments



$.get('myhtmlpage.html',myCallBack);



Here, the function myCallBack() is executed after the page ‘myhtmlpage.html’ is got from the server.


What the above Javascript code is doing is, It’s registering the function ‘myCallBack’ (notice that when you write it, it’s without () ), to the get event. i.e ‘myCallBack’ will be executed after the get is done.


 


Now, Consider a scenario wherein you need to register a callback function by passing arguments.


Do not try doing this, this is Wrong



$.get('myhtmlpage.html', myCallBack(param1, param2));



The above line won’t work because, myCallBack(param1,param2) is executed before it’s registered. In other words, The returned value of myCallBack(param1, param2) is registered as a callback function, which is not write.Javascript is expecting a function pointer here. so, the right way to do this will be to enclose  myCallBack(param1, param2) with function(){ }. Yes, you guessed it, that’s the anonymous function. (I’m really really found of this Javascript feature, sometimes it makes me think, that’s where languages like C# got the ideas from, C++ is an obvious choice Smile with tongue out)



$.get('myhtmlpage.html', function(){
myCallBack(param1, param2);
});

In the above example, an anonymous function is created (just a block of statements) and is registered as the callback function. Note the use of 'function(){'. The anonymous function does exactly one thing: calls myCallBack, with the values of param1 and param2 in the outer scope.


I’ll soon be writing more on jQuery and jQuery UI which i’ve started to use extensively off late. The following is worth reading for more.





Next Steps






















Thursday 27 November 2008

DI Management Cryptography

This page contains useful free cryptographic software code that David Ireland has written or adapted in Visual Basic and ANSI C. It's updated frequently, so keep checking.

http://www.di-mgt.com.au/crypto.html

Wednesday 26 November 2008

Tools for everyday development


1. Process Explorer
processexplorer
Process Explorer shows you information about which handles and DLLs processes have opened or loaded.
The Process Explorer display consists of two sub-windows. The top window always shows a list of the currently active processes, including the names of their owning accounts, whereas the information displayed in the bottom window depends on the mode that Process Explorer is in: if it is in handle mode you'll see the handles that the process selected in the top window has opened; if Process Explorer is in DLL mode you'll see the DLLs and memory-mapped files that the process has loaded. Process Explorer also has a powerful search capability that will quickly show you which processes have particular handles opened or DLLs loaded.

2. Debug View
debugview
DebugView is an application that lets you monitor debug output on your local system, or any computer on the network that you can reach via TCP/IP. It is capable of displaying both kernel-mode and Win32 debug output, so you don't need a debugger to catch the debug output your applications or device drivers generate, nor do you need to modify your applications or drivers to use non-standard debug output APIs.
Cool Features
  • Win32 OutputDebugString
  • Kernel-mode DbgPrint
  • All kernel-mode variants of DbgPrint implemented in Windows XP and Server 2003
DebugView also extracts kernel-mode debug output generated before a crash from Window's 2000/XP crash dump files if DebugView was capturing at the time of the crash.
3. PsKill
Windows NT/2000 does not come with a command-line 'kill' utility. You can get one in the Windows NT or Win2K Resource Kit, but the kit's utility can only terminate processes on the local computer. PsKill is a kill utility that not only does what the Resource Kit's version does, but can also kill processes on remote systems. You don't even have to install a client on the target computer to use PsKill to terminate a remote process.
P.S: Filemon and Regmon have been replaced by Process Monitor on versions of Windows starting with Windows 2000 SP4, Windows XP SP2, Windows Server 2003 SP1, and Windows Vista. Filemon and Regmon remain for legacy operating system support, including Windows 9x.
4. Resource Refactor
RefactoringTool-Menu
Features for Resource Refactoring Tool
  • Works with C#, VB.Net languages. Supports all project types that ships with Visual Studio 2005 including web sites and web application projects.
  • A preview window to show changes.
  • Finds other instances of the text being replaced in the project automatically.
  • Lists existing resources by their similarity level to the text being replaced.
  • Automatically replaces hard coded string with a reference to resource entry.
5. Ghost Doc
Automatically generates documentation for constructors,methods,properties and class. Integrates will with visual studio and style cop and is a must have to get rid of those style cop warnings.
6. Microsoft StyleCop
StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. This is a definite must have. It enforces consistent looking code across the whole project with multiple developers with varied tastes and preferences.
7. Microsoft FxCop
FxCop is an application that analyzes managed code assemblies (code that targets the .NET Framework common language runtime) and reports information about the assemblies, such as possible design, localization, performance, and security improvements. Many of the issues concern violations of the programming and design rules set forth in the Design Guidelines for Class Library Developers, which are the Microsoft guidelines for writing robust and easily maintainable code by using the .NET Framework.
FxCop is intended for class library developers. However, anyone creating applications that should comply with the .NET Framework best practices will benefit. FxCop is also useful as an educational tool for people who are new to the .NET Framework or who are unfamiliar with the .NET Framework Design Guidelines.
FxCop is designed to be fully integrated into the software development cycle and is distributed as both a fully featured application that has a graphical user interface (FxCop.exe) for interactive work, and a command-line tool (FxCopCmd.exe) suited for use as part of automated build processes or integrated with Microsoft Visual Studio® .NET as an external tool.

Links
Sysinternals Suite
FxCop
The Visual Studio Code Analysis Team Blog
StyleCop
Introducing StyleCop on legacy projects
Ghost Doc
Resource Refactor

Thursday 20 November 2008

Unit Testing Silverlight Apps

Inarguably SL2 applications are  a whole new experience of developing cross platform applications from managed code environments.

Unit Testing becomes very vital while developing for cross browser enterprise class applications. Visual Studio's tight integration of the Unit Testing framework is such an invaluable tool in the code production pipeline. Now, with the release of a unit testing framework for SL2 applications, the same experience can be leveraged.  SL2 applications can be developed in a test driven fashion now. It perfectly suits an agile team. A team which is constantly driven by change and is delivering on a constant basis, almost every day in some cases. Much like a team which does not have a release model. (Check out Jeff Wilcox's blog). I guess the Silverlight test framework was itself developed using an agile methodology.

The SL Unit testing framework has  proved to be an invaluable tool personally for me. It allows me to test SL applications on 3 different browsers (cheap guess if you are thinking which browsers ) even though i target IE mainly. :P.  I'll write about it with a test application soon in my next blog. Till then, check out these links..

Some Links:

Silverlight Toolkit - You can find components like dockpanel, treeview etc for SL 2, themes and of course the source code for controls with unit tests and the unit test framework itself.

Jeff Wilcox - The guy who develops actively on the SL unit test framework at MS.

Scott Gu's small demo program on SL unit testing - (If you don't know this man, you are not worth living, jump off a building NOW!)

MS Silverlight Unit Test Framework - MS unit test framework for SL 2.

Wednesday 19 November 2008

A good one

31340_strip_sunday

A Simple Multi-threaded Logger

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace SudhirMurthy.Logger {

public interface ILog {

void LogToDisk(string msg);

}

interface ILoggerService {
ILog ILog {
get;
}
}

public class LogFile : ILog {

static List<string> messages;

//WriteToDisk delegate
private delegate void WriteToDisk(object sender, string fileName);

//WriteToDisk event
private static event WriteToDisk writeToDisk;

public static void WriteLog(string fileName) {
//Raise the event
writeToDisk(new object(), (fileName));
}

public void SendToDisk(object sender, string fileName) {

StreamWriter sw = File.CreateText(fileName);
foreach (string s in messages) {
sw.WriteLine(s);
}
sw.Close();
}

public LogFile() {
messages = new List<string>();
WriteToDisk mydelegate = new WriteToDisk(SendToDisk);
writeToDisk = new WriteToDisk(SendToDisk);
}

public List<string> Messages {
get {
return messages;
}
}

#region ILog Members

public void LogToDisk(string msg) {
Monitor.Enter(this);
messages.Add(msg);
Monitor.Exit(this);
}

#endregion
}

public class LoggerService : ILoggerService {

//TODO: Need to make it threadsafe..
private static ILog logInstance = null;

public LoggerService() {
logInstance = new LogFile();
}

#region ILoggerService Members

public ILog ILog {
get {
return logInstance;
}
}

#endregion
}

public class LoggerClient1 {

LoggerService logService;

public LoggerClient1() {
logService = new LoggerService();
}

public void Log() {
logService.ILog.LogToDisk(string.Format(
"I am Logging: {0}", this.ToString()));
}
}

public class LoggerClient2 {
LoggerService logService;
public LoggerClient2() {
logService = new LoggerService();

}
public void Log() {
logService.ILog.LogToDisk(string.Format(
"I am Logging: {0}", this.ToString()));
}
}

public class TestApp {

LoggerClient1 a;
LoggerClient2 b;

public TestApp() {

a = new LoggerClient1();
b = new LoggerClient2();
}

public void logClient1() {
for (int i = 0; i < 1000000; i++) {
a.Log();
}
}

public void logClient2() {
for (int i = 0; i < 1000000; i++) {
b.Log();
}
}
}

class Program {

static void Main(string[] args) {

TestApp app = new TestApp();
Thread t1 = new Thread(new ThreadStart(app.logClient1));
Thread t2 = new Thread(new ThreadStart(app.logClient2));


try {
t1.Start();
t2.Start();
} catch (Exception) {
throw;
}
t1.Join();
t2.Join();

//The main thread should technically wait until
//t1 and t2 should have finished and then execute
//the following
LogFile.WriteLog("log.txt");
}

}

}



I have demonstrated a simple multi-threaded logging mechanism here. The threads t1 and t2 share the static instance variable 'List<string> messages' while logging. The LoggerClient classes LoggerClient1 and LoggerClient2 each use the LoggerService to log messages. The log is finally written to disk by the the main thread. The LogFile class uses the Monitor.Enter(this) and Monitor.Exit(this) methods to allow locking while shared access to writing the log. This synchronizes the threads t1 and t2 to perform shared access writes without corrupting or overlapping the write operations. Another important thing to notice here is the methods t1.Join() and t2.Join() which is used to make the main thread wait until the threads t1 and t2 have finished executing.


If you try removing the Monitor.Enter(this) and Monitor.Exit(this) lines from the above code, you end up getting weird line numbers in your log.txt file. (enable line no's in visual studio and see log.txt). i.e the count of the log will never be as expected (2 million in the above case). By putting the above lines back, you get the expected value which is 2million lines of log. :). It takes about 5-6 seconds on my dual core for threads t1 and t2 to finish logging and the main thread to write to disk. :).  A bloated 93.4 MB file!!



My thread on MSDN Forums.



C0de

Saturday 15 November 2008

Tricolor on the moon!!

2221255712_0f55253432

The probe, painted with the Indian flag, touched down at 2034 (1504 GMT) Friday the 14th of November 2008, the Indian Space Research Organisation (ISRO) said.

India has become the fourth nation to join the stuff-on-the-Moon club, after the Chandrayaan-1 spacecraft in lunar orbit successfully launched an impact probe at the lunar surface. The 35-kg impactor was blazoned with the Indian flag.

Mission Objectives

Carry out high resolution mapping of topographic features in 3D, distribution of various minerals and elemental chemical species including radioactive nuclides covering the entire lunar surface using a set of remote sensing payloads. The new set of data would help in unravelling mysteries about the origin and evolution of solar system in general and that of the moon in particular.

Realize the mission goal of harnessing the science payloads, lunar craft and the launch vehicle with suitable ground support system including DSN station, integration and testing, launching and achieving lunar orbit of ~100 km, in-orbit operation of experiments, communication/telecommand, telemetry data reception, quick look data and archival for scientific utilization by identified group of scientists.

 

chandrayaan-earth-tmc-2

chandrayaan-earth-tmc-1

chandrayaan-01 

Chandrayaan-1 spacecraft undergoing pre-launch tests

chandrayaan-03

Moon Impact Probe

 12

PSLV 11 Assembled and ready to go at sriharikota.

PSLV-C11-at-VAB

PSLV-C11 at Vehicle Assembly Building

PSLV-C11_Liftoff_ch6

INDIA SHOOTS TO THE MOON!. Photo of PSLV-C11 liftoff launching the Chandrayaan-1. 22 Oct 2008

MERA BHARAT MAHAAAAN! JAI HIND!

Chandrayaan - Payloads

Chandrayaan - Photo Gallery

Tricolor on the moon

Chandrayaan-1

Tuesday 11 November 2008

XHTML - A very simple primer.

XHTML is a reformulation of HTML in XML. XML is mainly made up of generic tags which can be used to define data. XHTML is derived from XML or putting it the other way, XML is the base for XHTML. XHTML is also very similar to HTML 4.1.

According to W3Schools,

“XHTML is a combination of HTML and XML (EXtensible Markup Language). XHTML consists of all the elements in HTML 4.01, combined with the strict syntax of XML.”

Tips to be XHTML 1.0 compliant

1. Start writing your tags and attribute names in lower cases

for eg. <BODY> - is wrong

<body> -  is correct.

<table WIDTH = “100%”> – is wrong

<table width = “100%” > – is correct

2. Always close your tags.

for eg. <p> this is a paragraph – is wrong

<p> this is a paragraph </p> – is correct

Be particularly aware when using tags like <img> <br> which do have a self closing tag in HTML 4.0,

These need to have a self-closing tag which is described as below.

<img src=”c:\\images\\alive.png”> – is wrong

<img src=”c:\\images\\alive.png” /> – is correct.

<br> – is wrong

<br/> – is correct

3. Nest your tags correctly

<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  <li>Milk</li>
</ul>

- is wrong

 

<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  </li>
  <li>Milk</li>
</ul>

- is correct

4. XHTML documents MUST have a root element - <html>

The document structure should look like

<html>
<head> ... </head>
<body> ... </body>
</html>

5. Attribute values MUST be in quotes

<div id=header >

</div> – is wrong

<div id=”header”>

</div> – is correct

<table width=”100%”> - is correct.

<table width=100%> -  is wrong.

6. Always add a  <!DOCTYPE> declaration to you page.

A DOCTYPE gives the browser information about the kind of HTML it expects.

The DOCTYPE declaration is always the first line in an XHTML document.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title> xhtml document</title>
</head>
<body>
<p> welcome to xhtml standards</p>
</body>
</html>

 

The XHTML DTD (Document type definition) defines the syntax of the XHTML markup.

 

XHTML 1.0 Strict

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

XHTML 1.0 Transitional

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Use the transitional DOCTYPE for valid markup and pages which render the same in all major browsers.

 

XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

Use the frameset DOCTYPE when you want to use HTML frames.

 

How w3schools was converted to xhtml

 

Useful Links

The XHTML 1.0 markup language (Second Edition) - http://www.w3.org/TR/xhtml1/ 

The XHTML Validator -  http://validator.w3.org/

W3School’s XHTML Tutorial -  http://www.w3schools.com/xhtml/

Monday 3 November 2008

The Numerati – Stephan Baker

They’ve Got Your Number

walker-500

Maybe you’re the kind of person who doesn’t believe that the kind of person you are can be deduced by an algorithm and expressed through shorthand categorizations like “urban youth” or “hearth keeper.”

Maybe I’d agree with you, and maybe we’re right. But the kind of people — “crack mathematicians, computer scientists and engineers” — whom Stephen Baker writes about in “The Numerati” clearly see things differently. NYTimes Article

Wednesday 22 October 2008

A Simple RSS Reader in WPF

I present here, a simple Rss reader written almost entirely in XAML. I personally find WPF Data binding powerful and exciting to work with.

To start with, i've used the XmlDataProvider class to hook up the source to an rss feed and set it's XPath property to "rss/channel/item", so that i get all items in the channel.

The layout is an utterly simple dockpanel which has a stackpanel docked to the top, a status bar docked to the bottom and a grid which fills up the remaining space.

The databinding is self explanatory with the following code.,However an important thing to note is that the <Textbox> which has the rss feed link is binded to the source directly. The 'UpdateSourceTrigger' property is by default set to LostFocus(). I've changed it to 'PropertyChanged', so that when a user enters an rss feed, the bindings get updated. Also notice that 'BindsDirectlyToSource' is set to True. Another interesting feature is the Master-Detail binding. Notice that between Line numbers 53-63. The listbox's selection is binded to  description and link which are textblocks inside a stack panel. Now, when the listbox gets focus, we bind the frame's source to the uri in the texbox.

I've added some styles to the listbox aswell. all of which could be found in the source code. This surely is very simple and yet a foundation to write a powerful rss reader in wpf. :)

We could add more rss feeds, write value converters, validation rules etc. as required.


Window1.xaml

   1: <Window x:Class="RssReader.Window1"


   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"


   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"


   4:     Title="RssReader" Height="600" Width="800">


   5:     


   6:     <Window.Resources>


   7:     <XmlDataProvider x:Key="rssdata"


   8:                      Source="http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml"


   9:                      XPath="rss/channel/item"/>


  10:         


  11:     </Window.Resources>


  12:     


  13:     <DockPanel   DataContext="{Binding Source={StaticResource rssdata}}">


  14:         <StackPanel DockPanel.Dock="Top"


  15:                     TextElement.FontWeight="Bold" Background="Gray">


  16:         


  17:             <TextBlock Text="{Binding XPath=./../title}"


  18:                     FontSize="20" Margin="10 10 10 0"/>


  19:             


  20:             <TextBlock Text="{Binding XPath=./../description}"


  21:                     FontSize="10" FontWeight="Normal" Margin="10 0"/>


  22:             


  23:             <TextBox Margin="5" Text="{Binding Source={StaticResource rssdata},                             


  24:                                 BindsDirectlyToSource=True,


  25:                                 Path=Source,


  26:                                 UpdateSourceTrigger=PropertyChanged}"/>


  27:         </StackPanel>


  28:  


  29:         <StatusBar DockPanel.Dock="Bottom">


  30:             <StatusBarItem Content="{Binding XPath=title}"/>


  31:             <Separator/>


  32:             <StatusBarItem Content="{Binding XPath=pubDate}"/>


  33:         </StatusBar>


  34:  


  35:         <Grid>


  36:             <Grid.ColumnDefinitions>


  37:                 <ColumnDefinition Width="25*"/>


  38:                 <ColumnDefinition Width="75*"/>


  39:                 <ColumnDefinition/>


  40:             </Grid.ColumnDefinitions>


  41:            


  42:             <ListBox Grid.Column="0" IsSynchronizedWithCurrentItem="True"                     


  43:                      ItemsSource="{Binding}" DisplayMemberPath="title"


  44:                      Style="{StaticResource ListBoxHand}"/>


  45:             <GridSplitter/>


  46:             


  47:             <Grid Grid.Column="1">


  48:                 <Grid.RowDefinitions>


  49:                     <RowDefinition Height="Auto"> </RowDefinition>


  50:                     <RowDefinition Height="85*"> </RowDefinition>


  51:                 </Grid.RowDefinitions>


  52:  


  53:                 <ListBox x:Name="selection" Grid.Row="0" IsSynchronizedWithCurrentItem="True"                         


  54:                          Style="{StaticResource SimpleListBox}"


  55:                          VerticalAlignment="Stretch"


  56:                          GotFocus="selection_GotFocus">


  57:                              


  58:                     <StackPanel>


  59:                             <TextBlock Text="{Binding XPath=description}" />


  60:                             <TextBlock x:Name="txtlink" Text="{Binding XPath=link}"/>


  61:                         </StackPanel>


  62:                 </ListBox>


  63:                     <Frame x:Name="Explorer" Grid.Row="1"/>


  64:             </Grid>


  65:         </Grid>


  66:  


  67:       </DockPanel>


  68:     </Window>


  69:  




Window1.xaml.cs





   1: private void selection_GotFocus(object sender, RoutedEventArgs e) {


   2:   Uri uri = new Uri(this.txtlink.Text.ToString());


   3:   this.Explorer.Source = uri;


   4: }


   5:   




Screenie



rssreader_wpf


C0d3 : here