Generic EventArgs

This has been done before but I think this is a cool tip that can save a heap of time and reduce the number of classes in your app.

There are a lot of times when you want to raise a quick event and just simply pass an value type or object as part of the EventArgs parameter. Instead of having to create separate EventArgs for every event you want to raise, we can create an EventArgs class that uses generics.


    public class EventArgs : EventArgs
    {
        public EventArgs(T value)
        {
            Value = value;
        }

        public T Value { get; set; }
    }

Usage:

    public event EventHandler<EventArgs<int>> SomeEventWithIntArg;

...

    if (SomeEventWithIntArg != null)
    {
        SomeEventWithIntArg(this, new EventArgs<int>(123));
    }

You can wire up the SomeIntEvent event and I will be able to access eventArgs.Value


    SomeEventWithIntArg += OnSomeEventWithIntArg;


    void OnSomeEventWithIntArg(object sender, EventArgs<int> eArgs)
    {
        int i = eArgs.Value;
    }

WPF Xceed Grid: How to prevent/disable validation for objects that implement IDataErrorInfo


From the Xceed documentation:

"Built-in support for IDataErrorInfo provides business-object level validation that can be used in combination with validation rules.

Unless the ValidationRules collection is cleared, it will always contain an ExceptionValidationRule and DataErrorValidationRule. If the DataErrorValidationRule is excluded from the collection of validation rules, validation errors reported by IDataErrorInfo will be ignored. "

The solution is to manually loop over the columns and clear the validators

    foreach(Column c in grid.Columns)
    {
                c.CellValidationRules.Clear();
    }