Click here to Skip to main content
15,861,125 members
Articles / Desktop Programming / WPF

WPF.MichaelAgroskin

Rate me:
Please Sign up or sign in to vote.
4.65/5 (8 votes)
6 Oct 2011Eclipse3 min read 28.1K   694   47   4
A free library of WPF controls and C# utility classes

Introduction

This page and the source code will be updated from time to time, so bookmark it and stay tuned.

Since the library is a work in progress, there could be a few undocumented classes and files. Ignore them please, or use at your risk. If it is not documented, it is probably not finished or not working properly yet.

Of course, the code can be used free of charge provided that the copyright statements stay intact. And of course, Michael Agroskin accepts no responsibility whatsoever for any crashes, errors, or data losses occurring as a result of using this library. Hopefully, there will be no such things, but better be safe than sorry.

Anyway, I hope that you will find those utility classes and controls very useful. At least, it won’t hurt you to take a look and maybe to learn something new. I created those classes out of sheer desperation when nothing else worked, and I have to use some of them every time I write the WPF stuff.

Library

  • {} Adorners
    • AdornerUtils.cs
    • TemplatedAdorner.cs
  • {} Animations
  • {} AutoComplete
    • AutoCompleteUtils.cs
  • {} Behaviours
    • EventBehaviourFactory.cs - Provides utility classes making it easy to execute commands when routed (or regular .NET) events are raised on WPF elements. Example of usage:
      C#
      public static class TextBoxBehaviour
      {
          public static readonly DependencyProperty TextChangedCommand = 
          RoutedEventBehaviourFactory.CreateCommandExecutionEventBehaviour
          (TextBox.TextChangedEvent, 
      	"TextChangedCommand", typeof (TextBoxBehaviour));     
          public static void SetTextChangedCommand
      		(DependencyObject o, ICommand value)
          {
              o.SetValue(TextChangedCommand, value);
          }
          public static ICommand GetTextChangedCommand(DependencyObject o)
          {
              return o.GetValue(TextChangedCommand) as ICommand;
          }
          // Optional
          public static readonly DependencyProperty TextChangedCommandParameter = 
          RoutedEventBehaviourFactory.CreateCommandParameter(TextChangedCommand);
          public static void SetTextChangedCommandParameter
      			(DependencyObject o, object value)
          {
              o.SetValue(TextChangedCommandParameter, value);
          }
          public static object GetTextChangedCommandParameter(DependencyObject o)
          {
              return o.GetValue(TextChangedCommandParameter);
          }
      }
      
          <textbox xxx:textchangedcommandparameter="{Binding ...}" 
      		xxx:textchangedcommand="{Binding SomeCommand}" />
  • {} Bindings
  • {} Collections
  • {} Commands
    • DelegateCommand.cs - Allows delegating the commanding logic to methods passed as parameters, and enables a View to bind commands to objects that are not part of the element tree (i.e. ViewModel). Very useful in conjunction with EventBehaviourFactory. See example:
      C#
      class ViewModel
      {
         public ICommand SomeCommand { get; private set; }
         public ViewModel()
         {
             SomeCommand = new DelegateCommand(
                () => { ... },
                () => { ... });
         }
      }
      <textbox xxx:textchangedcommand="{Binding SomeCommand}" />
      
    • TextBoxCommands.cs - Defines DefaultCommand (and DefaultCommandParameter) attached property which can be bound to ICommand and executed when Enter key is pressed. Idea is similar to EventBehaviourFactory.
  • {} Common
  • {} Converters
    • AddConverter.cs
    • BooleanValueConverter.cs
    • BrushValueConverter.cs
    • ByteValueConverter.cs
    • CharValueConverter.cs
    • ColorValueConverter.cs
    • CombineFlagsConverter.cs
    • ConverterEnums.cs
    • DateTimeValueConverter.cs
    • DecimalValueConverter.cs
    • DelegateConverter.cs
    • DelegateMultiConverter.cs
    • DoubleValueConverter.cs
    • EditableFlagsToBooleanConverter.cs
    • EnumToBooleanConverter.cs
    • EnumValueConverter.cs
    • FlagsToBooleanConverter.cs
    • GridLengthValueConverter.cs
    • NotConverter.cs
    • ObjectToObjectConverter.cs
    • ThicknessValueConverter.cs
    • TimeSpanValueConverter.cs
  • {} Delegates
  • {} DragDrop
    • DataConsumer.cs
    • DataConsumerFactory.cs
    • DataObjectBase.cs
    • DataProvider.cs
    • DataProviderFactory.cs
    • DataTransfer.cs
    • DragDropConsts.cs
  • {} Extensions
    • BooleanExtension.cs – Allows to define Booleans inline in any context (and don't rely on the correct TypeConverter). Especially useful when the type of property is "object", i.e., no TypeConverter is used at all. See example:
      XML
      <setter value="{ext:Boolean True}" property="..." />
    • DateTimeExtension.cs - See above
    • DoubleExtension.cs - See above
    • EnumExtension.cs - See above
    • Int32Extension.cs - See above
  • {} Helpers
    • DelayedAction.cs
    • DelegateEqualityComparer.cs
    • DummyTypeConverter.cs
    • LookupItem.cs
    • Ref.cs
    • Serializer.cs
    • WindowBehavior.cs
  • {} Menus
    • CompositeContextMenu.cs
    • CompositeMenu.cs
    • CompositeMenuItem.cs
    • FlatteningMenuItems.cs
  • {} ReadOnly
    • ReadOnlyClone.cs
    • ReadOnlyCloneFactory.cs
  • {} Threading
    • MultiThreadedWrapper.cs
    • ThreadedVisualHelper.cs
    • ThreadingUtils.cs
  • {} Visuals
    • VisualTargetPresentationSource.cs
    • VisualWrapper.cs
  • {} WeakEvents

License

This article, along with any associated source code and files, is licensed under The Eclipse Public License 1.0


Written By
Software Developer (Senior) Liquidnet
United States United States
Michael is a software developer who still remembers punch cards, computers with 4 Kbytes RAM, and 3270s. His personal computers were Apple IIe, Commodore, and PC XT (with the whole 640 Kbytes RAM and 2 floppy drives!!!). Wow, that was a powerhouse.

Fast forward 32 years through FORTRAN, PL-I, Algol, Pascal, Prolog, LISP, C, Basic, Clipper, Assembly, FoxPro, DHTML, JavaScript, C++, you name it, to C# 4.0.

Of course, real men use machine code to write software, but what a difference a few years make! No more mallocs and callocs, GC magically collects unused objects, dynamic objects magically call IUnknown::QueryInterface, Reflection magically gives you metadata and even generates help files, WPF magically binds stuff together...

Read some of Michael's articles here.

BindingHub (a WPF component and a design pattern) [^].

Notifying parent of changes to children's properties [^].

Point-In-Time database (coming soon)

Composite Menus and other ItemsControls (coming soon)

Adorners framework (coming soon)

Drag-n-drop data transfer framework (coming soon)

Converters and MarkupExtensions (coming soon)

Download complete WPF library [^].

Comments and Discussions

 
GeneralMy vote of 5 Pin
fredatcodeproject6-Oct-11 23:32
professionalfredatcodeproject6-Oct-11 23:32 
GeneralRe: My vote of 5 Pin
RugbyLeague7-Oct-11 3:08
RugbyLeague7-Oct-11 3:08 
GeneralMy vote of 5 Pin
Hari Om Prakash Sharma6-Oct-11 17:53
Hari Om Prakash Sharma6-Oct-11 17:53 
GeneralMy vote of 5 Pin
Wooters6-Oct-11 13:18
Wooters6-Oct-11 13:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.