XCEED Datagrid

June 2, 2009

is changing licensing for the express edition. I’ve been using XCEED’s datagrid control for WPF for a year now, because it was the best grid control I could find, and for some of the controls for Date Time and numeric included in the library.

XCEED is changing licensing for the express edition and  has launched a campain in order to notify everyone interested in the express edition and still wants to have the benefits he had before the change.

So just visit http://xceed.com/freegrid and update your license.


Enable / Disable Binding Validation

February 20, 2009

Today a came across a situation where I need to stop a binding from validating through the validation rules.

There is no easy way to do this. One should think that you can change the hole binding etc etc.

After doing a little snipping while in debug, I saw that the BindingExpression return from BindingExpression GetBindingExpression(DependencyPropertydp) holds in the ParentBinding.ValidationRules the validation rules declared in xaml or not.

So I decided to create a BaseValidationRule from which all validation rules will subclass.

public abstract classBaseValidationRule:ValidationRule
  
{
        protected BaseValidationRule()
        {
            IsActive = true;
        }
        public bool IsActive { get; set; }

        protected abstract ValidationResult DoValidate(objectvalue,
System.Globalization.CultureInfocultureInfo);
        public overrideValidationResult Validate(objectvalue,
System.Globalization.CultureInfo cultureInfo)
        {
            if(!IsActive)
            {
                returnValidationResult.ValidResult;
            }
            return DoValidate(value, cultureInfo);
        }
    }

 

As you can see if the rule is not active then it will simply return a ValidationResult.ValidResult so everything will be as though as you didn’t have validation rules in xaml.

I created some extention methods in order to quickly and transparently enable or disable validation rules at will.

Note that in order for the binding to be reevaluated based on the new status of your validation rules, you need to call UpdateSource on you BindingExpression .


WPF vs Windows Forms

November 25, 2008

Today I was at a DevDay in Athens, Greece with subject the 3 W of .NET 3 and 3.5. WPF, WCF and WWF.

First of all, I want to say that for one for time, it was just like reading glorious posts on the net about how easy stuff are with Microsoft technologies. Guys, business applications are not a paper for a university lesson. Programmers in companies should not be carried away by tricks that show of, but not give a resolve issues that enterprise developers must solve.

Based on that, once again WCF was great. Hell its not because of reasons discussed  here and here. In the WWF, a colleague of mine asked a very logical question, but there was no answer either. I don’t know whether those presenting the technologies don’t have a deep understanding of the technologies discussed or they purpose is to market them.

In the subject that I understand best, that is WPF, I really must say that based on what was presented, no one would migrate to the technology. The speaker made the usual mistake of basing his presentation on the usual wrong stuff, Graphic, Animation Fantastic UI and the so called developer – designer better cooperation. But when a member of the audience asked the logical question, of why should I migrate,  when all there are so huge differences and especially when a dedicated designer will be required still there was no clear answer to point out that true power of WPF.

So I will try to point out what are the overwhelming advantages of WPF and also point out some of the wrongs that I have found in the last six months.

Yes there is a tough learning curve, but the true power of WPF resides in the data binding mechanism and the way it shares resources across the application. On extra benefit that comes from the learning curve is that who learn how to decouple logic from UI. It’s not because of a pattern, but because of the data binding mechanism. Truly an application will last longer, when the UI can be changed without producing problems to the logic. Use the templates right and you can change a piece of UI code that reflects to the entire application. And don’t get me started about the usage of Control Templates.

Routed events are also great but the resource sharing is awesome. Just create a themed application in windows forms and compare the memory used by heavy brushes with a WPF themed application.

All the above comes with greatly improved performance, bonus from .NET 3.5 SP1.

My first problem with WPF and with Microsoft is the total disregard for Datasets and especially typed datasets. WPF will be on a client which if it is an enterprise application, it will require an application server. What better way to have related data transferred over the wire than from dataset? This is why I say that Microsoft has great ideas, but tends to forget the real needs of business. All examples are with simple objects which have set and get methods. But that is the simple way. That would be the solution for a university exercise because in real world you cant hit the application server continually, wcf or not.

Second problem with WPF is the Command mechanism that is used. Don’t get me wrong, the idea is great but why it must be static the Command instance? If I want to create the same form twice as non modal window, what will happen? It is not clear to me why they have chosen static for commands.

For the last six months I’ve been developing with colleagues a WPF application that can handle several modules not known at design time, and all these modules and the shell can must present themselves in various languages based on the installation. I really don’t know how some things could have been made with windows forms.

For me WPF and WCF are the most powerful add-ons in the .NET3 version and older. I just wish Microsoft would be a little more serious about the needs of true enterprise applications and not just glowingly showing little demos.


WPF Themes

November 19, 2008

I knew for a time that Visual State Manager from Silverlight had been ported for WPF, via the WPF.Toolkit project.

Today I found out that there some interesting themes based on the Visual State Manager.

Here is the post

I especially like DavesGlossyControls


WPF ShowDialog

September 12, 2008

There is an issue with ShowDialog for Windows not always obeying Modal Dialogs rules.

So I have created a static class which all ShowDialog calls will be redirected.

public static bool ShowDialog(Window dialog,Window owner)
{
    if (owner != null)
    {
        WindowInteropHelper helper = new WindowInteropHelper(dialog);
        helper.Owner = new WindowInteropHelper(owner).Handle;
    }
    bool? dialogResult = dialog.ShowDialog();
    return dialogResult.HasValue ? dialogResult.Value : false;
}

 

I’ve made some corrections so this is the new code

public static bool ShowDialog(Windowdialog, Windowowner)
{
   WindowInteropHelper helper = newWindowInteropHelper(dialog);
   if(owner != null)
   {
      helper.Owner = newWindowInteropHelper(owner).Handle;
   }
   else
  
{
      helper.Owner = GetActiveWindowClass.GetActiveWindow();
   }
   bool? dialogResult = dialog.ShowDialog();
   returndialogResult.HasValue ? dialogResult.Value : false;
}

where GetActiveWindowClass.GetActiveWindow is a interop wrapper

public static class GetActiveWindowClass
{
    [DllImport("user32.dll")]
    public static extern IntPtr GetActiveWindow();
}

 
 
 
 


Set a value to a control only in design mode

June 14, 2008

I have been working on making my project localizable. I made it using Resources just like skins but this will be another post.

The final problem I encountered was that there was no design time support to show a dummy text, in a Button for example. Everything was going well except from the design part which was not that significant for me, but as I’m the writer of the company’s new framework it might be for others.

So can you set a value to DependencyProperty of a DependencyObject only to in DesignMode?

Using a custom MarkupExtension you can. Here is the implementation

[ContentProperty("Value")]
public class  DesignTimeDummy : MarkupExtension
{
    public DesignTimeDummy()    {

    }
    public object  Value { get; set; }
    public override object  ProvideValue
          (IServiceProvider serviceProvider)
    {
        if (Helpers.Designer.InDesignMode)
        {

            return Value;

        }
        return DependencyProperty.UnsetValue;
    }

}

And this is how you can use it

<Button Style=”{DynamicResource styleName}” Content=”{CoreME:DesignTimeDummy Value=DesignContentValue}”/>

or

<Button Style="{DynamicResource cancelButtonStyle}" >
  <Button.Content>
    <CoreME:DesignTimeDummy>
      Dummy
    </CoreME:DesignTimeDummy>
  </Button.Content>
</Button>

where CoreME is an xmlns defined namespace shortcut

 


In design mode

June 14, 2008

WPF project has begun and I have been continuously finding new things. I’m very excited, mainly because what I have accomplished to today. Maybe I will write about it.

Many thanks to fellows like Josh,Karl and Sasha for the knowledge I have acquired from them since Summer 2007.

One of the things I needed, for my next post, is to know if code is running in DesignMode or not.

So here is the class I wrote

public static class Designer
{
    private static DependencyObject dummy = new DependencyObject();
    public static bool InDesignMode
    {
        get { return DesignerProperties.GetIsInDesignMode(dummy); }
    }
}


Karl on ASP vs WPF

December 21, 2007

Karl Shifflett has posted a very interesting post, regarding what architecture to choose for a new Application Project

His post can be found here and my comments here