<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>SeeSharp - SeeSharp</title>
        <description>A C# development blog</description>
        <link>/SeeSharp/RSS</link>
        <language>en</language>
        <image>
            <url>http://www.hightech.ir/favicon.png</url>
            <title>SeeSharp</title>
            <link>/SeeSharp/RSS</link>
            <width>64</width>
            <height>64</height>
        </image>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/SeeSharp" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <dc:creator>HEskandari</dc:creator>
            <title>Reflecting on Interface Inheritance</title>
            <description>The other day I was working on an interceptor that listened to calls to some &amp;ldquo;Services&amp;rdquo; and redirected the calls to services hosted on remote machine, instead of running it locally when strangest thing happened. I was trying to find and invoke existing methods on my interface that according to reflection, were not there. Those services were using inherited interface:

&lt;pre class="brush:c-sharp"&gt;
public interface IServiceBase&amp;lt;T&amp;gt;
{
   T FindOne(Criteria c);
   
   T[] FindMany(Criteria c);
}

public interface ICustomerService : IServiceBase&amp;lt;Customer&amp;gt;
{
    Customer FindByName(string name);
}
&lt;/pre&gt;

I was trying to get methods of ICustomerSerivce defined and inherited from the base interface:

&lt;pre class="brush:c-sharp"&gt;
[TestMethod]
public void Can_Find_Base_Method_On_Interface()
{
    var service = typeof (ICustomerService);
    var method = service.GetMethod("FindOne");

    Assert.IsNotNull(method);
}
&lt;/pre&gt;

Unfortunately, this fails! It seems reflection does not work consistently on inherited interfaces. To solve this, you'd have all the base methods &amp;ldquo;redefined&amp;rdquo;, which becomes very nasty if you have multiple interface inheritances, or if you extensively use generics on interface level. So changing the above code to this will make the test go green:

&lt;pre class="brush:c-sharp"&gt;
public interface ICustomerService : IServiceBase&amp;lt;Customer&amp;gt;
{
    Customer FindByName(string name);
    
    new Customer FindOne(Criteria c);
   
    new Customer[] FindMany(Criteria c);
}
&lt;/pre&gt;

I still don't know why this behavior, or maybe this is a known issue?
&lt;br /&gt;&lt;br/&gt;
&lt;em&gt;&lt;strong&gt;Update&lt;/strong&gt;: Found out that the behavior in fact is inline with ECMA CLI specifications. You can however check the methods on Interface's other interfaces. See a solution &lt;a href="http://stackoverflow.com/questions/358835/getproperties-to-return-all-properties-for-an-interface-inheritance-hierarchy"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/qIaHRJt_FgI" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/qIaHRJt_FgI/Reflecting-On-Interface-Inheritance</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/Reflecting-On-Interface-Inheritance</guid>
            <pubDate>Tue, 06 Oct 2009 07:01:00 GMT</pubDate>
            <category>Reflection</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/Reflecting-On-Interface-Inheritance</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>Anatomy of an ASP.NET MVC Control</title>
            <description>One of the great things about ASP.NET WebForms was that it wasy very easy to creat reuseable custom controls and components, but with appearance of ASP.NET MVC and lots of developers moving towards it, which is a good thing, what happens to component oriented development? Is is possible to create custom controls in MVC? Can we port our existing controls to MVC? ASP.NET MVC while may not be as good as WebForms when it comes to drag-and-drop style of using components, but it is fairly easy to use and to create custom controls in MVC! Let's see how.

To create a control in WebForms world, you'd extend the existing &lt;em&gt;WebControl&lt;/em&gt; class and override Render method which takes a HtmlTextWriter that you can use to output the desired HTML code to the browser. A control rendering &lt;em&gt;Hello World&lt;/em&gt; on the screen would be as simple as this:

&lt;pre class="brush:c-sharp"&gt;
public class HelloWorldControl : WebControl 
{
    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        
        writer.Write("&amp;lt;span&amp;gt;HelloWorld&amp;lt;/span&amp;gt;");
    }
}
&lt;/pre&gt;

You'd put this on your web page and you're all set. But what's the best approach in MVC controls? There's no WebControl or Control classes inside Mvc assemblies, so can either use any existing class you have as a base class or it from scratch. 

&lt;pre class="brush:c-sharp"&gt;
public class WebControl
{
    /// &amp;lt;summary&amp;gt;
    /// Renders the control by writing the html code into the text writer.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="textWriter"&amp;gt;&amp;lt;/param&amp;gt;
    public virtual void Render(TextWriter textWriter)
    {
    }
    
    /// &amp;lt;summary&amp;gt;
    /// Renders the control and outputs the generated HTML code.
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    public string OnRender()
    {
        var tw = new StringWriter();
        
        Render(tw);
        
        return tw.ToString();
    }
}
&lt;/pre&gt;

With this, you have a ready to use base class for your controls. You need to override the Render method and construct the right HTML code. The code would look almost identical:

&lt;pre class="brush:c-sharp"&gt;
public class HelloWorldControl : WebControl
{
    public override void Render(TextWriter writer)
    {
        base.Render(writer);
        
        writer.Write("&amp;lt;span&amp;gt;Hello World!&amp;lt;/span&amp;gt;");
    }
}
&lt;/pre&gt;

Note: There's a catch here. We'd use existing methods on HtmlTextWriter in WebForms, which emitted correct HTML code per Browser. If you're writing the HTML code manually (as I did in this example) you'd be careful in case you need to support different browsers.

How do we use this in an MVC application you might ask? The way to do this, as it is already done in the MVC framework with other controls such as TextBox, CheckBox, etc. is to create an extension method on HtmlHelper class:

&lt;pre class="brush:c-sharp"&gt;
public static class HelloWorldControlExtensions
{
    public static string HelloWorld(this HtmlHelper helper)
    {
        var control = new HelloWorldControl();
        
        return control.OnRender();
    }
}
&lt;/pre&gt;
Now you can add this controls to your views, as easy as other controls such as TextBoxes:
&lt;pre class="brush:c-sharp"&gt;
&amp;lt;%= Html.HelloWorld() %&amp;gt;
&lt;/pre&gt;

That's almost it. The only thing remaining here is to implement control specific logic of your components and that part is left to you.&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/NCUThJ9mMv0" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/NCUThJ9mMv0/anatomy-of-aspnet-mvc-control</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/anatomy-of-aspnet-mvc-control</guid>
            <pubDate>Tue, 08 Sep 2009 15:49:00 GMT</pubDate>
            <category>ASPNETMVC</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/anatomy-of-aspnet-mvc-control</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>Caliburn = Less Code?</title>
            <description>&lt;a href="http://www.codeplex.com/caliburn"&gt;Caliburn&lt;/a&gt; is an application framework for WPF / Silverlight. If you're developing applications for these platforms, there are many reasons why you definitely need to be using this framework, but today, I noticed how using this framework resulted writing less code while doing more. Let's see how writing a small WPF application using &lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel"&gt;MVVM&lt;/a&gt; pattern is different when using &lt;a href="http://www.codeplex.com/caliburn"&gt;Caliburn&lt;/a&gt;.
&lt;i&gt;&lt;b&gt;Note: There are many other ways to skin a cat. This is how I do things, there may be other, better ways to do the same thing.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="subtitle"&gt;Application Startup&lt;/span&gt;&lt;br /&gt;When creating an application using MVVM and &lt;em&gt;&lt;a href="http://wildermuth.com/2009/05/22/Which_came_first_the_View_or_the_Model"&gt;ViewModel First&lt;/a&gt;&lt;/em&gt; development, you'd create the root View and VM, bind them through DataContext and show the main window of the application.  &lt;br /&gt;&lt;br /&gt;
&lt;pre class="brush:c-sharp"&gt;
///
/// Interaction logic for App.xaml
///
public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        
        var container = new WindsorContainer();
        var rootView = new RootView();
        var rootModel = new RootViewModel();
        
        rootView.DataContext = rootModel;
        this.MainWindow = rootView;
        this.MainWindow.Show();
    }
}
&lt;/pre&gt;
With caliburn, all you need to do is to create the root VM. There's no trace of any View creation and binding the DataContext to VM. All this is done automatically by Caliburn. To do this, use &lt;em&gt;&lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=Application"&gt;CaliburnApplication&lt;/a&gt;&lt;/em&gt; as your base application class which will configure Caliburn framework upon startup. There are &lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=Project%20Setup&amp;amp;referringTitle=Home"&gt;other ways&lt;/a&gt; to do the configuration but let's stick to this simple configuration scenario that installs default implementations of Calburn &lt;em&gt;Components&lt;/em&gt;.&lt;br /&gt;
&lt;pre class="brush:c-sharp"&gt;
///
/// Interaction logic for App.xaml
///
public partial class App : CaliburnApplication
{
    protected override IServiceLocator CreateContainer()
    {
        var container = new WindsorContainer();
        var adapter = new WindsorAdapter(container);
        
        return adapter;
    }
    
    protected override object CreateRootModel()
    {
        return new RootViewModel();
    }
}
&lt;/pre&gt;
One thing a little different is that Caliburn uses &lt;a href="http://msdn.microsoft.com/en-us/library/dd458913.aspx"&gt;IServiceLocator&lt;/a&gt; insterface (from &lt;a href="http://www.codeplex.com/CommonServiceLocator/"&gt;Common Service Locator&lt;/a&gt;) and has no direct dependency on a vendor specific &lt;a href="http://martinfowler.com/articles/injection.html"&gt;IoC Container&lt;/a&gt;, which is a good thing. This means, you can choose various IoC containers and adapters for major IoC containers like &lt;a href="http://www.castleproject.org/container/index.html"&gt;Windsor&lt;/a&gt;, &lt;a href="http://ninject.org/"&gt;Ninject&lt;/a&gt;, &lt;a href="http://code.google.com/p/autofac/"&gt;Autofac&lt;/a&gt;, etc. are already included in Caliburn bits. If you're not a fan of IoC containers and won't be using one in your application (now, come on!), Caliburn uses a lightweight built-in container, in case you don't specify any other.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0080c0; font-size: 100%;"&gt;&lt;b&gt;Actions and Commands&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;Should you bind an action to a ICommand instance on the VM, in pure MVVM application you would bind the &lt;a href="http://msdn.microsoft.com/en-us/library/ms752308.aspx"&gt;Command&lt;/a&gt; property to an &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.aspx"&gt;ICommand&lt;/a&gt; instance on the VM. You can specify the condition on which the command will be executable and you'll also implement the action execute by the command.&lt;br /&gt;
&lt;pre class="brush:c-sharp"&gt;
&amp;lt;Button Command="{Binding ExitCommand}" Content="Exit Application"&amp;gt;

public class RootViewModel : BaseViewModel
{
    private ICommand _exitCommand;
    public ICommand ExitCommand
    {
        get
        {
            if (_exitCommand == null)
                _exitCommand = new RelayCommand(this.Exit, this.CanExit);
            
            return _exitCommand;
        }
    }
    
    public bool CanExit()
    {
        return true;
    }
    
    public void Exit()
    {
        Application.Current.Shutdown();
    }
}
&lt;/pre&gt;
Notice there are other &lt;em&gt;hidden&lt;/em&gt; code here too. You'll need to create a new Command, or use &lt;a href="http://www.codeproject.com/KB/WPF/VMCommanding.aspx"&gt;RelayCommand&lt;/a&gt; (kudos to &lt;a href="http://joshsmithonwpf.wordpress.com/"&gt;Josh&lt;/a&gt;) and you probably need a common &lt;a href="http://martinfowler.com/eaaCatalog/layerSupertype.html"&gt;layer supertype&lt;/a&gt; that implements &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx"&gt;INotifyPropertyChanged&lt;/a&gt;&lt;i&gt;&lt;/i&gt; interface. Using Caliburn you'd bind the &lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=Action%20Basics&amp;amp;referringTitle=Home"&gt;action&lt;/a&gt; directly to the VM and there's no dependency to ICommand instances. The good thing is, you're not limited to Command property anymore and you can bind various other events such as Click, MouseOver, etc. to actions on your VM.&lt;br /&gt;
&lt;pre name="code" class="brush:c-sharp"&gt;
&amp;lt;Button cal:Message.Attach="[Event Click] = [Action Exit]" Content="Exit Application"&amp;gt;

public class RootViewModel : Presenter
{
    public bool CanExit()
    {
        return true;
    }
    
    public void Exit()
    {
        Application.Current.Shutdown();
    }
}
&lt;/pre&gt;
There are lots of existing boilerplate functionalities already available in Caliburn, so you can drop BaseViewModel and use &lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=IPresenter%20Component%20Model"&gt;Presenter&lt;/a&gt; class (IPresenter implementation).&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0080c0; font-size: 100%;"&gt;&lt;b&gt;Displaying Views&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;To display other views in the RootView (e.g. Shell), we'd constructed a new VM and set it to a Content property of a ContentControl. This will actually pick up the view specified in the DataTemplate from Application Resources, and display it on the UI. You have to maintain a mapping between your Views and your VMs in a resource dictionary and as your application grows this gets harder to maintain.&lt;br /&gt;
&lt;pre name="code" class="brush:c-sharp"&gt;
&amp;lt;Application.Resources&amp;gt;
    &amp;lt;DataTemplate DataType="{x:Type vm:CustomerViewModel}"&amp;gt;
        &amp;lt;view:CustomerView /&amp;gt;
    &amp;lt;/DataTemplate&amp;gt;
&amp;lt;/Application.Resources&amp;gt;

&amp;lt;ContentControl Content="{Binding Path=CurrentView}"/&amp;gt;

public class RootViewModel : BaseViewModel
{
    public void ShowCustomer()
    {
        CurrentView = IoC.Resolve&amp;lt;Customerviewmodel&amp;gt;();
    }
    
    private BaseViewModel _currentView;
    public BaseViewModel CurrentView
    {
        get { return _currentView; }
        set
        {
            _currentView = value;
            RaisePropertyChanged("CurrentView");
        }
    }
}
&lt;/pre&gt;
Let's see how we can do this using Caliburn. First off, we do not need to maintain any ViewModel mapping if we name our Views and ViewModels according to the Caliburn &lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=IBinder%20and%20Convention%20over%20Configuration"&gt;Conventions&lt;/a&gt; that is, your view names should ending in View, presenters / VMs ending in &lt;em&gt;ViewModel&lt;/em&gt;or &lt;em&gt;Presenter&lt;/em&gt; and each should be in a separate namespace, namingly &lt;em&gt;Views&lt;/em&gt; and &lt;em&gt;ViewModels&lt;/em&gt; or &lt;em&gt;Presenters&lt;/em&gt;. This is just by convention and you can always override if you need to. Caliburn will automatically create the view for you, set the &lt;em&gt;CurrentPresenter&lt;/em&gt; property on the main window (i.e. &lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=IPresenter%20Component%20Model"&gt;IPresenterHost&lt;/a&gt;) and do any required bindings. Did I mention you don't need the whole mapping of View &amp;lt;-&amp;gt; &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx"&gt;DataTemplate&lt;/a&gt; in your Application / Form resource?&lt;br /&gt;
&lt;pre name="code" class="brush:c-sharp"&gt;
&amp;lt;ContentControl x:Name="CurrentPresenter" &amp;gt;

[Singleton("RootViewModel")]
public class RootViewModel : PresenterManager
{
    public void ShowCustomer()
    {
        var presenter = ServiceLocator.Current.GetInstance&amp;lt;Customerviewmodel&amp;gt;();
        this.Open(presenter);
    }
}
&lt;/pre&gt;

&lt;span style="color: #0080c0; font-size: 100%;"&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;What's the catch? How does Caliburn do this? Caliburn uses &lt;em&gt;&lt;a href="http://caliburn.codeplex.com/Wiki/View.aspx?title=IBinder%20and%20Convention%20over%20Configuration"&gt;Convention over Configuration&lt;/a&gt;&lt;/em&gt; pattern, so if you do things according to the convention you'll end up saving a lot of code. There's always the possibility to change the default behavior too. By complying to these conventions, clearly you'll end up writing less code, but more importantly the code you do write is cleaner, more robust and probably with better testabilty. With the help of &lt;em&gt;Binding Tests&lt;/em&gt; utilities existing in Caliburn, you can test your bindings the easy way, which is some thought for later posts.&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/aiVgJSFcUIs" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/aiVgJSFcUIs/caliburn-less-code</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/caliburn-less-code</guid>
            <pubDate>Wed, 02 Sep 2009 11:59:00 GMT</pubDate>
            <category>MVVM</category>
            <category>WPF</category>
            <category>Caliburn</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/caliburn-less-code</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>Windsor Registration : Service Interface</title>
            <description>&lt;p&gt;Sometimes when registering classes on Windsor container, that extend an existing base class with an interface, using auto registration and FirstInterface method is useless, because first interface finds the interface implemented by base class:&lt;/p&gt;  

&lt;pre class="brush:c-sharp"&gt;
[TestFixture]
public class RegistrationFixture : ContainerTest
{
    [Test]
    public void Can_Find_Service_Using_Interface()
    {
        var service = TryResolve&amp;lt;IService&amp;gt;();

        Assert.That(service, Is.Not.Null);
    }

    protected override void OnSetup()
    {
        base.OnSetup();

        Container.Register(AllTypes.From(typeof(ServiceImpl))
                     .Where(null)
                     .Configure(x =&gt; x.LifeStyle.Is(LifestyleType.Transient))
                     .WithService.FirstInterface());
    }
 
    private interface IBaseService
    {
    }

    private interface IService
    {
    }

    private class BaseService : IBaseService
    {
    }

    private class ServiceImpl : BaseService, IService
    {
    }
}
&lt;/pre&gt;
If you run the test, it will fail, because ServiceImpl is registered with IBaseService interface, which is the first interface on the class hierarchy. But that is not what I intended to do. I wanted the to register it using the first interface on the same type, e.g. IService. Extension methods come to the rescue:&lt;br /&gt;

&lt;pre class="brush:c-sharp"&gt;
public static class ContainerExtensions
{
   public static BasedOnDescriptor FirstInterfaceOnClass(this ServiceDescriptor serviceDescriptor)
   {
       return serviceDescriptor.Select((t, bt) =&amp;gt;
       {
           var baseInterfaces = t.BaseType.GetInterfaces();
           var interfaces = t.GetInterfaces().Except(baseInterfaces);

           return interfaces.Count() != 0 ? new[] {interfaces.First()} : null;
       });
   }
}
&lt;/pre&gt;
Changing the registration to this would pass the failing test:&lt;br /&gt;
&lt;pre class="brush:c-sharp"&gt;
    Container.Register(AllTypes.From(typeof(ServiceImpl))
                 .Where(null)
                 .Configure(x =&amp;gt; x.LifeStyle.Is(LifestyleType.Transient))
                 .WithService.FirstInterfaceOfClass());
&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/gg0V2svyNRc" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/gg0V2svyNRc/windsor-registration-service-interface</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/windsor-registration-service-interface</guid>
            <pubDate>Thu, 20 Aug 2009 12:08:00 GMT</pubDate>
            <category>Windsor</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/windsor-registration-service-interface</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>LOB Application in WPF</title>
            <description>&lt;p&gt;I've been working on a small LoB application to manage sales of a small sales office. I thought it'd be a good idea to put to use my WPF knowledge and use WPF to create this application. The reason is obvious : Programming in WPF is as easy as it gets, more testable (as in Unit Testing and Acceptance Testing) and more end-user friendly. &lt;/p&gt;  &lt;p&gt;Following applicaiton components and patterns were used:&lt;/p&gt;  &lt;ul class="square"&gt;   &lt;li&gt;NHibernate &lt;/li&gt;    &lt;li&gt;NHibernate Validator to validate both entities and ViewModels &lt;/li&gt;    &lt;li&gt;FarsiLibrary (globalizing Dates, DatePickers, etc.) &lt;/li&gt;    &lt;li&gt;MVVM pattern &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="color:#0080ff;"&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;One part that took more effort than expected was localization and globalization of the application. In general, there are three things you need to check to achieve full localization, if you provide both Left-To-Right reading order languages (English) as well as Right-To-Left (Farsi, Arabic) :&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;&lt;span style="color:#0080ff;"&gt;Flow Direction&lt;/span&gt;&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;Thanks to WPF engine, most of the calculation of LTR reading order to RTL for Forms, UserControls and even Custom Controls is done automagically, although in custom controls, you might need to add some triggers to switch things like shadows, etc. and if you use a 3rd party custom control or library, you need to make sure component vendor has take care of issue like that.&lt;/p&gt;    &lt;h4&gt;&lt;strong&gt;&lt;span style="color:#0080ff;"&gt;Texts&lt;/span&gt;&lt;/strong&gt;&lt;/h4&gt;    &lt;p&gt;WPF uses LocaBaml to extract localizable properties' values to an excel file and  after translation (e.g. assigning values for other languages), puts them in a  satelite assembly. This approach looks rough to maintain but there are lots of  libraries on Codeplex that will help you do this with xml files or .resx files. My suggestion is to use &lt;a href="http://wpflocalizeextension.codeplex.com/"&gt;WPF Localization Extension&lt;/a&gt; which supports localizing FlowDirection, Brush, Texts, Images, etc.&lt;br /&gt;&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;&lt;span style="color:#0080ff;"&gt;Dates&lt;/span&gt;&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;Not eveyone use Gregorian Calendar available in english language cultures. For example in Arabic language HijriCalendar is used and for Farsi, PersianCalendar is used and sometimes just setting thread's culture to the language (e.g. Farsi) would not be enough. If you use dates in your applications (who doesn't?) you need to use date controls that work fluently with various languages and cultures. I used my own &lt;a href="http://blog.hightech.ir/search/label/FarsiLibrary"&gt;FarsiLibrary control for WPF&lt;/a&gt; which allows you to work with PersianCalendar, HijriCalendar and GregorianCalendar seamlessly.&lt;/p&gt;    &lt;h4&gt;&lt;strong&gt;&lt;span style="color:#0080ff;"&gt;System Messages&lt;/span&gt;&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;With all the efforts and steps mentioned above, one part of the application still remains in native language of the Windows Installation. That is when using Windows's MessageBox to alert user and display messages. Fortunately, I already have my Expression Clone styles which come with a Expression style messagebox that come with localizable icons / button texts. &lt;/p&gt; &lt;center&gt;   &lt;table border="0" cellpadding="0" cellspacing="0" width="500"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td align="left" valign="top"&gt;&lt;a href="http://lh3.ggpht.com/_Z5KTIfnfuNs/SnFbnFTpc4I/AAAAAAAAAQA/kXkyVSgQMzk/s1600-h/ScreenShot003%5B5%5D.png"&gt;&lt;img title="Waring_English_MsgBox" alt="Waring_English_MsgBox" src="http://lh4.ggpht.com/_Z5KTIfnfuNs/SnFbpAM22II/AAAAAAAAAQE/ZmmOhorU3xM/ScreenShot003_thumb%5B3%5D.png?imgmax=800" border="0" height="93" width="218" /&gt;&lt;/a&gt;&lt;/td&gt;          &lt;td align="left" valign="top"&gt;&lt;a href="http://lh4.ggpht.com/_Z5KTIfnfuNs/SnFbqh50bFI/AAAAAAAAAQI/KSQGM9kar1o/s1600-h/ScreenShot002%5B9%5D.png"&gt;&lt;img title="Warning_Persian_MsgBox" alt="Warning_Persian_MsgBox" src="http://lh4.ggpht.com/_Z5KTIfnfuNs/SnFbsPkK3bI/AAAAAAAAAQM/d7XeMazXDqE/ScreenShot002_thumb%5B7%5D.png?imgmax=800" border="0" height="94" width="244" /&gt;&lt;/a&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/center&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="color:#0080ff;"&gt;Styling&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;      &lt;p&gt;No doubt one of the features that comes with WPF is the ability to style everything that makes sense to provide a better UX. I used my &lt;a href="http://blog.hightech.ir/2008/04/expression-clone.html"&gt;Expression styles&lt;/a&gt; which you can download &lt;a href="http://blog.hightech.ir/2008/04/expression-clone.html"&gt;here&lt;/a&gt; to style your WPF applications very easily to make it look like Expression series.&lt;br /&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://lh6.ggpht.com/_Z5KTIfnfuNs/SnFbvKJcDuI/AAAAAAAAAQQ/YV8S_HkzPd0/s1600-h/ScreenShot001%5B7%5D.png"&gt;&lt;img style="border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;" title="Before Styling" alt="Before Styling" src="http://lh5.ggpht.com/_Z5KTIfnfuNs/SnFbyHL7C0I/AAAAAAAAAQU/aD5Sm5efyT8/ScreenShot001_thumb%5B5%5D.png?imgmax=800" border="0" height="361" width="500" /&gt;&lt;/a&gt;&lt;span style="font-style: italic;font-size:78%;" &gt;Before Styling&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;     &lt;div style="text-align: center;"&gt;&lt;a href="http://lh5.ggpht.com/_Z5KTIfnfuNs/SnFb4LjrRLI/AAAAAAAAAQY/oBAonC9WY_Q/s1600-h/ScreenShot001%5B8%5D.png"&gt;&lt;img style="border-width: 0px; display: block; float: none; margin-left: auto; margin-right: auto;" title="After Styling" alt="After Styling" src="http://lh3.ggpht.com/_Z5KTIfnfuNs/SnFczyKmthI/AAAAAAAAAQg/OfxoBPEQoB0/ScreenShot001_thumb%5B6%5D.png?imgmax=800" border="0" height="403" width="500" /&gt;&lt;/a&gt;&lt;span style="font-style: italic;font-size:78%;" &gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;Using Expression Styles&lt;/span&gt;  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6069495622049300789-1082298095406063296?l=heskandari.blogspot.com'/&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/VsIAjON5C-w" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/VsIAjON5C-w/lob-application-in-wpf</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/lob-application-in-wpf</guid>
            <pubDate>Thu, 30 Jul 2009 13:11:00 GMT</pubDate>
            <category>General</category>
            <category>WPF</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/lob-application-in-wpf</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>XamDataGrid Validation with NHibernate Validator</title>
            <description>&lt;p&gt;One of the good grid controls in WPF world belongs to Infragistics. With all the bells and whistles, there are still some limitation, some are WPF engine limitation and some are not. One thing that is very limiting is validation of data prior them being added to datasource. This is rather a broad subject, but I intended to use NHibernate entities (POCO objects) decorated with NHiberante validator attributes to do the validation for me. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;span class="subtitle"&gt;NHibernate Validator&lt;/span&gt;&lt;br/&gt;
&lt;p&gt;NHibernate Validator is a subproject in &lt;a href="http://sourceforge.net/projects/nhcontrib/"&gt;NHibernate Contrib&lt;/a&gt; which allows you validate plain business classes by using predefined set of validation attributes. The good thing is, as good as NHibernate uses &lt;a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object"&gt;POCO&lt;/a&gt; (Plain Old CLR Object) objects you can also validate any kind of simple classes using NHibernate validator. There are other validation frameworks out there but I didn't wanted to clutter my object with the validation mechanism and I also didn't want to write unnecessary properties on my domain objects (e.g. IsValid, etc.) so NHibernate Validator was a right choice for me. Let's see how a POCO entity along with validation looks like:

&lt;pre class="brush:c-sharp"&gt;
public class Product
{
    public Product()
    {
    }

    public long ProductId
    {
        get;
        private set;
    }

    [NotNullNotEmpty]
    public string Title
    {
        get; set;
    }

    [NotNull]
    public Category Category
    {
        get; set;
    }

    public string Description
    {
        get; set;
    }

    [Min(0)]
    public long Quantity
    {
        get; set;
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;span class="subtitle"&gt;Binding To XamDataGrid&lt;/span&gt;&lt;br/&gt;
&lt;p&gt;&lt;a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamdatagrid.aspx"&gt;XamDataGrid&lt;/a&gt; supports binding to &lt;a href="http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspx"&gt;IEnumerable&lt;/a&gt;&lt;em&gt;&lt;/em&gt; interface, so an &lt;em&gt;IList&amp;lt;Product&amp;gt;&lt;/em&gt; would work. Also, XamDataGrid needs a public parameterless constructor if you're going to add to that collection from the grid control. If this requirement is not met, grid control will silently ignore the NewLine setting value. Here's the xaml snippet to display a grid with predefined fields (columns) and a NewLine row:&lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
&amp;lt;igdp:XamDataGrid DataSource="{Binding ProductList}"&amp;gt;
    &amp;lt;igdp:XamDataGrid.FieldLayouts&amp;gt;
        &amp;lt;igdp:FieldLayout&amp;gt;
            &amp;lt;igdp:FieldLayout.Settings&amp;gt;
                &amp;lt;igdp:FieldLayoutSettings AddNewRecordLocation="OnTopFixed" AllowDelete="False"
                             AllowAddNew="True" ExpansionIndicatorDisplayMode="Never"
                /&amp;gt;
            &amp;lt;/igdp:FieldLayout.Settings&amp;gt;
            &amp;lt;igdp:FieldLayout.Fields&amp;gt;
                &amp;lt;igdp:Field Name="Title"       Label="Product Name" /&amp;gt;
                &amp;lt;igdp:Field Name="Category"    Label="Category" /&amp;gt;
                &amp;lt;igdp:Field Name="Description" Label="Comment"/&amp;gt;
                &amp;lt;igdp:Field Name="Quantity"    Label="Qtty" /&amp;gt;
                &amp;lt;igdp:Field Name="ProductId"   Visibility="Collapsed"/&amp;gt;
            &amp;lt;/igdp:FieldLayout.Fields&amp;gt;
        &amp;lt;/igdp:FieldLayout&amp;gt;
    &amp;lt;/igdp:XamDataGrid.FieldLayouts&amp;gt;
&amp;lt;/igdp:XamDataGrid&amp;gt;
&lt;/pre&gt;
Now when you run the application and add a new Product object to the datasource, there's no way to check if all the predefined validation rules are okay. So, how do we change the behavior of the grid control to:&lt;br /&gt;
  
&lt;ul class='square'&gt;
  &lt;li&gt;Validate the product object PRIOR being added to the datasource so if an object is not validate, it won't get added to the data source.&lt;br /&gt;&lt;br/&gt;&lt;/li&gt;
  &lt;li&gt;No redundant validation code should be written. We need to use NHibernate Validator infrastructure we already have in place.&lt;br /&gt;&lt;br/&gt;&lt;/li&gt;
  &lt;li&gt;A reusable mechanism. Our application might end up with lots of grid controls.&lt;br /&gt;&lt;br/&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One way would be to subclass the grid control which although might work, is a heavy handed solution to our rather little problem. It is not right to put the code in our ViewModel (I'm using &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;MVVM pattern&lt;/a&gt;), which introduces coupling betwee UI and ViewModel. Fortunately, this grid control exposes good events we can tap into and change the default validation behavior and we can do this by creating a new Attached Behavior.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;

&lt;span class="subtitle"&gt;Validation Attached Behavior&lt;/span&gt;&lt;br/&gt;&lt;p&gt;Attaching a behavior to an object, as the name puts it, means making the object do something that it would not do by default. According to &lt;a href="http://joshsmithonwpf.wordpress.com/"&gt;Josh Smith&lt;/a&gt;:&lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;ldquo;The idea is that you set an attached property on an element so that you can gain access to the element from the class that exposes the attached property. Once that class has access to the element, it can hook events on it and, in response to those events firing, make the element do things that it normally would not do. It is a very convenient alternative to creating and using subclasses, and is very XAML-friendly.&amp;rdquo;&lt;/p&gt;&lt;/blockquote&gt; and that's exactly what we're going to do. We're going to listen to one event in particular : &amp;ldquo;RecordUpdating&amp;rdquo; which fires when the user had edited an item and the control wants to submit the changes back to the data source. Here's the part that does the validation:&lt;br /&gt;&lt;br /&gt;
&lt;pre class="brush:c-sharp"&gt;
private static void OnRecordUpdating(object sender, RoutedEventArgs e)
{
    var arg = (RecordUpdatingEventArgs)e;
    var dataobject = arg.Record.DataItem;
    var rules = GetAllInvalidRules(dataobject);
    var grid = (XamDataGrid)sender;

    if (rules != null &amp;&amp; rules.Count &gt; 0)
    {
        var propertyName = rules[0].PropertyPath;
        var propertyTitle = grid.DefaultFieldLayout.Fields[propertyName].Label;

        arg.Action = RecordUpdatingAction.CancelUpdateRetainChanges;
        arg.Record.Tag = string.Format("Check Field : {0}", propertyTitle);
    }
    else
    {
        arg.Record.Tag = null;
    }

    e.Handled = true;
}
&lt;/pre&gt;

&lt;h4&gt;&lt;em&gt;Note : We only display one error at a time. If you need to display all of them at once, you can do so by changing the code a little bit.&lt;/em&gt;&lt;/h4&gt;

We place the error information on the Record object's Tag information. In our little RecordSelector style, we'll display an error icon in case Tag property is set to some error information:&lt;br /&gt;

&lt;pre class="brush:c-sharp"&gt;
&amp;lt;Style TargetType="{x:Type igdp:RecordSelector}"&amp;gt;
    &amp;lt;Setter Property="Template"&amp;gt;
        &amp;lt;Setter.Value&amp;gt;
            &amp;lt;ControlTemplate TargetType="{x:Type igdp:RecordSelector}"&amp;gt;
                &amp;lt;Image x:Name="ErrorIcon" Source="pack://application:,,,/GridValidation;component/Images/FieldError.png"
                 Width="16" Height="16" Margin="4,0,0,0" Visibility="Collapsed" ToolTip="{Binding Tag}" /&amp;gt;
                &amp;lt;ControlTemplate.Triggers&amp;gt;
                    &amp;lt;DataTrigger Binding="{Binding Path=Tag, Converter={StaticResource DefaultNullConverter}}" Value="False"&amp;gt;
                        &amp;lt;Setter TargetName="ErrorIcon" Property="Visibility" Value="Visible" /&amp;gt;
                    &amp;lt;/DataTrigger&amp;gt;
                &amp;lt;/ControlTemplate.Triggers&amp;gt;
            &amp;lt;/ControlTemplate&amp;gt;
        &amp;lt;/Setter.Value&amp;gt;
    &amp;lt;/Setter&amp;gt;
&amp;lt;/Style&amp;gt;
&lt;/pre&gt;

One last thing that is remaining, is to connect our attached behavior to our xamDataGrid control. The great thing about the attached behaviors (one of them, at least) is that you can use them from XAML code directly and no code-behind is required at all. So back to our xamDataGrid code, here's how to do the trick:&lt;br /&gt;
&lt;pre class="brush:c-sharp"&gt;
&amp;lt;igdp:XamDataGrid DataSource="{Binding ProductList}"
                                 bhv:DataGridValidationBehavior.HasRowValidation="true"&amp;gt;
&lt;/pre&gt;

&lt;span class="subtitle"&gt;Conclusion&lt;/span&gt;&lt;br/&gt;The final application looks like this picture. If you try to enter something wrong, either when creating a new item or editing one, validation mechanism will automagically kick in and does the work for you. The very important point is that data is retained in the new line but is it not added to the datasource, because the data is not validated. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_Z5KTIfnfuNs/SmcIfVGFI1I/AAAAAAAAAP4/REI4BmqG1C4/s1600-h/xamGrid-Validation%5B7%5D.png"&gt;&lt;img style="border: 0px none ; display: inline;" title="xamGrid-Validation" alt="xamGrid-Validation" src="http://lh5.ggpht.com/_Z5KTIfnfuNs/SmcIhWEs9yI/AAAAAAAAAP8/CMK6zn-7le0/xamGrid-Validation_thumb%5B5%5D.png?imgmax=800" border="0" height="292" width="464" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can download the source code from &lt;a href="http://cid-4962b6ceabc2cbd7.skydrive.live.com/self.aspx/BlogFiles/Misc/Infragistics.GridValidation.zip"&gt;here&lt;/a&gt;. In order to fully compile and run the application, you need to install Infragistics WPF components which you can download &lt;a href="http://www.infragistics.com/downloads/default.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/HrJPPJIW_rk" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/HrJPPJIW_rk/xamdatagrid-validation-with-nhibernate</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/xamdatagrid-validation-with-nhibernate</guid>
            <pubDate>Wed, 22 Jul 2009 17:09:00 GMT</pubDate>
            <category>NHibernateValidator</category>
            <category>xamDataGrid</category>
            <category>WPF</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/xamdatagrid-validation-with-nhibernate</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>Infragistics WPF Reporting</title>
            <description>&lt;p&gt;I've been looking for flexible Reporting components for the WPF application I'm working on, and strangely enough, there are just a few. I think WPF component in general is still a work in progress, and even if you have the chance to find a working component, there ALL have a lot of short comings and lack design-mode features, developer-friendliness, etc. and when it comes down to reporting component, there is &lt;a href="http://www.infragistics.com/dotnet/netadvantage/wpf/reporting.aspx"&gt;Infragistics&lt;/a&gt; with very basic feature set, &lt;a href="http://www.componentone.com"&gt;ComponentOne&lt;/a&gt; with years of background in reporting tools and &lt;a href="http://www.stimulsoft.com/"&gt;Stimulsoft&lt;/a&gt; with complete reporting set for WinForm, WPF and Web. &lt;/p&gt;

&lt;p&gt;So, I start evaluating each one. Stimusoft WPF reporting looked very promising with all bells and whistles like end-user WPF designer and the whole UI (designer and preview) were in WPF, but If I'm going to buy a component I need more that just a reporting tool, how about having bunch of other controls as well? I skipped to ComponentOne and after downloading their package (around 100 MB download), the damn installation did not work and I was staring at the installation error message that had to do something with packaging. So in reality, I had only one more choice : Infragistics. &lt;/p&gt;&lt;br /&gt;

&lt;span class="subtitle"&gt;Infragistics Reporting&lt;/span&gt;&lt;br/&gt;
&lt;p&gt;With very basic feature, Infragistics reporting is also easy to use. Since there is no designer (yet?) you have to code your report and create various report sections (Header, Footer, etc.) and add related stuff into that sections, all in code. The great thing about this reporting control (also a feature of ComponentOne) is that you can print any kind of UIElement, this means you can print your whole UserControl or Form which comes in handy. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_Z5KTIfnfuNs/SlsQzr0-TmI/AAAAAAAAAPs/07hfZWtQtKw/s1600-h/Infragistics-Reporting%5B11%5D.jpg"&gt;&lt;img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="Infragistics-Reporting" alt="Infragistics-Reporting" src="http://lh4.ggpht.com/_Z5KTIfnfuNs/SlsQ5HsoPII/AAAAAAAAAPw/nyiJgngkmrY/Infragistics-Reporting_thumb%5B9%5D.jpg?imgmax=800" border="0" width="200" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The real power of Infragistics reporting is when combined with their &amp;ldquo;Data Presenter&amp;rdquo; or &amp;ldquo;XamDataGrid&amp;rdquo; control. End-user can apply filtering, grouping, sorting, etc. and just print the result, easy as that.&lt;/p&gt;

&lt;span class="subtitle"&gt;RightToLeft Issue&lt;/span&gt;&lt;br/&gt;
&lt;p&gt;When evaluating my application which is a multi-lingual application that supports RightToLeft and LeftToRight reading ordered languages, I came across a problem when printing controls with RightToLeft flow direction. The problem was that the whole control is &amp;ldquo;Mirrored&amp;rdquo;. Not that this mirroring is an issue, but all the texts and values printed are also mirrored which makes the whole report useless.&lt;/p&gt;  &lt;p&gt;&lt;img style="border: 0px none ; display: block; float: none; margin-left: auto; margin-right: auto;" title="Mirrorred Report" alt="Mirrorred Report" src="http://lh6.ggpht.com/_Z5KTIfnfuNs/SlsQ74ejcdI/AAAAAAAAAP0/X9Z4uML9wzI/IFG-Mirrorred%20Report_thumb%5B3%5D.jpg?imgmax=800" border="0" width="419" /&gt;&lt;/p&gt;

&lt;span class="subtitle"&gt;Workaround&lt;/span&gt;&lt;br/&gt;
&lt;p&gt;The workaround is, of course, not to print the control in RightToLeft and use LeftToRight for the time being until the bug is fixed. As easy as this sounds, it is not very easy to do for some reasons:&lt;/p&gt;
&lt;ul&gt;
   &lt;li&gt;RightToLeft is usually set on the parent (Form), and controls just &amp;ldquo;inherit&amp;rdquo; the setting from their parent.&lt;/li&gt;
   &lt;li&gt;If you do change parent's RightToLeft end-user will see the effect. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But you can always clone the object and change the behavior, right? But you can not do so with Visual Elements. There's no Copy / Clone method on Visual elements in WPF, so how do we &amp;ldquo;clone&amp;rdquo; the control, change the FlowDirection, and hand it to the reporting?&lt;/p&gt;  &lt;p&gt;Fortunately, WPF comes with two neglected classes : &amp;ldquo;XamlWriter&amp;rdquo; and &amp;ldquo;XamlReader&amp;rdquo; each of which do as exactly as the name puts it. Using &amp;ldquo;XamlWriter&amp;rdquo; you can write a Visual object (UIElement) into a string, then use &amp;ldquo;XamlReader&amp;rdquo; ton construct it back. This is just about the UI, so you'll have to re-attach the &amp;ldquo;DataSource&amp;rdquo; and &amp;ldquo;DataContext&amp;rdquo; you might have. Here's the snippet to do the trick:&lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
public XamDataGrid Clone(XamDataGrid printable)
{
    //Clone the grid control
    var o = XamlWriter.Save(printable);
    var sr = new StringReader(o);
    var reader = XmlReader.Create(sr, new XmlReaderSettings());
    var result = (XamDataGrid)XamlReader.Load(reader);

    //It's a clone, need to reassign data source
    result.DataSource = printable.DataSource;

    //Set flow direction to LTR
    result.FlowDirection = FlowDirection.LeftToRight;

    return result;
}
&lt;/pre&gt;
You can &lt;a href="http://cid-4962b6ceabc2cbd7.skydrive.live.com/self.aspx/BlogFiles/Misc/Infragistics.ReportingRTLDemo.zip"&gt;download&lt;/a&gt; the whole sample that shows the issue and the workaround. To compile and run it you need to have Infragistics 2009.1 installed. You can download Infragistics package &lt;a href="http://www.infragistics.com/downloads/default.aspx"&gt;here&lt;/a&gt;.&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/GjKyRV-JaIA" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/GjKyRV-JaIA/infragistics-wpf-reporting</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/infragistics-wpf-reporting</guid>
            <pubDate>Mon, 13 Jul 2009 15:18:00 GMT</pubDate>
            <category>WPF</category>
            <category>Reporting</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/infragistics-wpf-reporting</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>Additional CallContext information in WCF</title>
            <description>&lt;p&gt;Yeah, this might be a little old, but someone asked me how to send context information from client to the service with WCF.&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: In general, you should not rely on client provided information about security, authentication, licensing, etc. Use this code and sample as an idea on how to implement your custom security. If you're trying to send sensitive information over the network, use this at your own risk.&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;WCF client and services might be (and probably are) in two separate AppDomain or even on separate machines across the network, so how do we send extra information from the client to the service when the service call is made? Fortunately, WCF provides enough extensibility points for us to participate in the action and change the default behavior. It is pretty much easy to add context information to the message header on the client side, and the on the server side extract the custom data from the message header. Added data to the message header can be a DataContract / Serialized class. &lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
[DataContract]
public class MessageInfo
{
   public MessageInfo(Guid sessionId, CultureInfo culture, DateTime requestDate)
   {
       this.sessionId = sessionId;
       this.culture = culture;
       this.requestDate = requestDate;
   }

   [DataMember]
   public DateTime RequestDate
   {
       get;
       set;
   }

   [DataMember]
   public Guid SessionId
   {
       get;
       set;
   }

   [DataMember]
   public CultureInfo Culture
   {
       get;
       set;
   }
}
&lt;/pre&gt;

Client uses IClientMessageInspector to add context data before the message is handed over to WCF for the delivery.&lt;br /&gt;

&lt;pre class="brush:c-sharp"&gt;
/// &lt;summary&gt;
/// Flows the client's MessageInfo to the service.
/// &lt;/summary&gt;
public class ClientMessageInfoInspector : IClientMessageInspector
{
   public object BeforeSendRequest(ref Message request, IClientChannel channel)
   {
       request.Headers.Add(MessageHeader.CreateHeader(MessageHeaderKeys.MessageInfoKey, string.Empty, GetInfo()));
       return null;
   }

   public void AfterReceiveReply(ref Message reply, object correlationState)
   {
   }

   private MessageInfo GetInfo()
   {
       return new MessageInfo(Guid.NewGuid(), Thread.CurrentThread.CurrentUICulture, DateTime.Now);
   }
}
&lt;/pre&gt;

On the other hand, the service side uses IDispatchMessageInspector interface to extract the data from message header.&lt;br /&gt;

&lt;pre class="brush:c-sharp"&gt;
/// &lt;summary&gt;
/// Reads the MessageInfo of client and updates the service.
/// &lt;/summary&gt;
public class ServiceMessageInfoInspector : IDispatchMessageInspector
{
   public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
   {
       int headerIndex = request.Headers.FindHeader(MessageHeaderKeys.MessageInfoKey, string.Empty);
       if (headerIndex != -1)
       {
           MessageInfo ui = request.Headers.GetHeader&amp;lt;MessageInfo&amp;gt;(headerIndex);
          
           Thread.CurrentThread.CurrentUICulture = ui.Culture;
           Thread.CurrentThread.CurrentCulture = ui.Culture;

            Console.WriteLine("Request recieved on {0}", ui.RequestDate);
       }

       return null;
   }

   public void BeforeSendReply(ref Message reply, object correlationState)
   {
   }
}
&lt;/pre&gt;

&lt;p&gt;To wire things up, you also need to create a new behavior by implementing IEndpointBehavior and registering it with your endpoint, either by code, or configuration. Should you use a single behavior for both client and server, here's how to do it:&lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
public class MessageInfoBehavior : IEndpointBehavior
{
   public void Validate(ServiceEndpoint endpoint)
   {
   }

   public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
   {
   }

   public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
   {
       ServiceMessageInfoInspector inspector = new ServiceMessageInfoInspector();
       endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
   }

   public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
   {
       ClientMessageInfoInspector inspector = new ClientMessageInfoInspector();
       clientRuntime.MessageInspectors.Add(inspector);
   }
}
&lt;/pre&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/nfPH3rDsTMc" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/nfPH3rDsTMc/additional-callcontext-information-in</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/additional-callcontext-information-in</guid>
            <pubDate>Sun, 05 Jul 2009 12:07:00 GMT</pubDate>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/additional-callcontext-information-in</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>File Download with ASP.NET MVC</title>
            <description>&lt;p&gt;One of the things that might be less obvious when doing applications with ASP.NET MVC, is the ability to download files without exposing your files directly and possibly applying other mechanisms such as authentication or registering emails before allowing someone download your files. This is pretty much easy. The "Controller" class has a File method which returns a "FilePathResult".&lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
public class DownloadsController : Controller
{
    private readonly IProductService _productService;

    public DownloadsController(IProductService productService)
    {
        _productService = productService;
    }

    [SessionPerRequest]
    public ActionResult Index()
    {
        var products = _productService.GetDownloadableProducts();
        var model = new DownloadViewModel(products);

        return View(model);
    }

    [SessionPerRequest]
    public ActionResult File(int id)
    {
        var download = _productService.FindDownload(id);

        if (download != null)
        {
            var path = Server.MapPath(download.URL);
            var file = new FileInfo(path);
            if (file.Exists)
            {
                return File(download.URL, "application/binary", download.FileName);
            }
        }

        return RedirectToAction("Index");
    }
}
&lt;/pre&gt;

&lt;br/&gt;

&lt;pre class="brush:c-sharp"&gt;
&amp;lt;table&amp;gt;
   
    &amp;lt;% foreach (var p in Model.Products) { %&amp;gt;
         &amp;lt;tr&amp;gt;
           &amp;lt;td&amp;gt;
             &amp;lt;strong&amp;gt;&amp;lt;%= p.Title %&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;
              
             &amp;lt;%foreach(var d in p.Downloads) { %&amp;gt;
               
                &amp;lt;a href="/Downloads/File/&amp;lt;%= d.Id %&amp;gt;"&amp;gt;
                   Version: &amp;lt;%= d.Version %&amp;gt;- &amp;lt;%= d.DownloadSize %&amp;gt; KB
                &amp;lt;/a&amp;gt;
                &amp;lt;br /&amp;gt;
            &amp;lt;%} %&amp;gt;
               
           &amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
     &amp;lt;% } %&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/VBSU02SX3hs" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/VBSU02SX3hs/file-download-with-aspnet-mvc</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/file-download-with-aspnet-mvc</guid>
            <pubDate>Tue, 23 Jun 2009 10:45:00 GMT</pubDate>
            <category>ASPNETMVC</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/file-download-with-aspnet-mvc</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>NHibernate JetDriver : Another Issue</title>
            <description>&lt;p&gt;There is yet another issue with NHibernate and JetDriver I encountered yesterday. It seems that a select query containing "Order By", will gets its "From" keyword cut off at some stage by the Jet Driver. It means simple object querying won't work:&lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
public IList&amp;lt;Account&amp;gt; GetAllAccounts()
{
  using (UnitOfWork.Start())
  {
      var repository = new NHRepository&amp;lt;Account&amp;gt;();
      var orders = new[] { new Order("Firstname", true), new Order("Lastname", true) };

      return repository.FindAll(orders).ToList();
  }
}
&lt;/pre&gt;

&lt;p&gt;To fix it, let's first pin point the problem by creating a failing test. It was a good thing I was already running everything from the trunk build, so I opened up the JetDriver project (from NHContrib) and luckily there is already a test project. Since I didn't want to actually change any method visibility, I used reflection to call the private methods that fails this test:&lt;/p&gt;

&lt;pre class="brush:c-sharp"&gt;
[TestFixture]
public class JetOrderByFixture
{
  [Test]
  public void Select_Statement_With_OrderBy_Should_Run()
  {
      SqlString sql = new SqlString("SELECT * FROM ACCOUNTS ORDER BY Firstname ASC, Lastname ASC");
      JetDriver driver = new JetDriver();

      SqlString processedSql = driver.GetType()
                                     .GetMethod("FinalizeJoins", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod)
                                     .Invoke(driver, new object[] { sql }) as SqlString;

      Assert.That(processedSql, Is.Not.Null);
      Assert.That(processedSql.LastIndexOfCaseInsensitive("FROM"), Is.GreaterThan(0));
  }
}
&lt;/pre&gt;

&lt;p&gt;The problem is the private FinalizeJoins method, so the test, to no surprise, fails. I have created a &lt;a href="http://nhjira.koah.net/browse/NHCD-33"&gt;task&lt;/a&gt; in NHibernate's Jira and the patch to fix this is attached, if you need it.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/-8BUTd1tylM" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/-8BUTd1tylM/nhibernate-jetdriver-another-issue</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/nhibernate-jetdriver-another-issue</guid>
            <pubDate>Tue, 26 May 2009 10:50:00 GMT</pubDate>
            <category>NHibernate</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/nhibernate-jetdriver-another-issue</feedburner:origLink></item>
        <item>
            <dc:creator>HEskandari</dc:creator>
            <title>Unit Testing with TypeMock</title>
            <description>&lt;p&gt;&lt;a href="http://www.typemock.com/"&gt;Unit Testing&lt;/a&gt; ASP.NET? &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;ASP.NET unit testing&lt;/a&gt; has never been this easy. &lt;/p&gt;  &lt;p&gt;Typemock is launching a new product for ASP.NET developers : the ASP.NET Bundle - and for the launch will be giving out FREE licenses to bloggers and their readers. &lt;/p&gt;  &lt;p&gt;The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both &lt;a href="http://www.typemock.com/"&gt;Typemock Isolator&lt;/a&gt;, a &lt;a href="http://www.typemock.com/"&gt;unit test&lt;/a&gt; tool and &lt;a href="http://sm-art.biz/Ivonna.aspx"&gt;Ivonna&lt;/a&gt;, the Isolator add-on for &lt;a href="http://sm-art.biz/Ivonna.aspx"&gt;ASP.NET unit testing&lt;/a&gt;, for a bargain price. &lt;/p&gt;  &lt;p&gt;Typemock Isolator is a leading &lt;a href="http://www.typemock.com/"&gt;.NET unit testing&lt;/a&gt; tool (C# and VB.NET) for many â€˜hard to testâ€™ technologies such as &lt;a href="http://typemock.com/sharepointpage.php"&gt;SharePoint&lt;/a&gt;, &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;ASP.NET&lt;/a&gt;, &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;MVC&lt;/a&gt;, &lt;a href="http://www.typemock.com/wcfpage.php"&gt;WCF&lt;/a&gt;, WPF, &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;Silverlight&lt;/a&gt; and more. Note that for &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;unit testing Silverlight&lt;/a&gt; there is an open source Isolator add-on called &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;SilverUnit&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;The first 60 bloggers who will blog this text in their blog and &lt;a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html"&gt;tell us about it&lt;/a&gt;, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator + Ivonna). If you post this in an ASP.NET dedicated blog, you'll get a license automatically (even if more than 60 submit) during the first week of this announcement. &lt;/p&gt;  &lt;p&gt;Also 8 bloggers will get an additional 2 licenses (each) to give away to their readers / friends. &lt;/p&gt;  &lt;p&gt;Go ahead, click the following link for &lt;a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html"&gt;more information&lt;/a&gt; on how to get your free license.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/SeeSharp/~4/LuQGl1gXTS4" height="1" width="1"/&gt;</description>
            <link>http://feedproxy.google.com/~r/SeeSharp/~3/LuQGl1gXTS4/unit-testing-with-typemock</link>
            <guid isPermaLink="false">http://www.hightech.ir/SeeSharp/unit-testing-with-typemock</guid>
            <pubDate>Thu, 21 May 2009 13:31:00 GMT</pubDate>
            <category>Testing</category>
        <feedburner:origLink>http://www.hightech.ir/SeeSharp/unit-testing-with-typemock</feedburner:origLink></item>
    </channel>
</rss>
