Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WPF

WPF.MichaelAgroskin

4.65/5 (8 votes)
6 Oct 2011Eclipse3 min read 28.9K   703  
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