Posts

Showing posts from February, 2013

C# How to create generic List with dynamic type

Given the Type typeof( Item ) (defined below), how would you create a list of Items using Reflection in C#? var  type =  typeof ( Item ); IList  listOfItems = ( IList ) Activator .CreateInstance( typeof ( List <>).MakeGenericType(type));   public   class   Item {      public   string  Name {  get ;  set ; } }     

WPF InputBindings KeyBinding Command Example .Net 4.0

Image
WPF starting from .Net Framework 4.0 allows developers to bind commands directly to the KeyBindings as shown in the example below: A complete solution is posted here on my Google Drive:  https://docs.google.com/file/d/0Bw72YL7u1BpmaFdsSng1N3Rqbnc/edit?usp=sharing < Window  x : Class = "WPF_InputBindings_Keybinding.MainWindow"          xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns : x = "http://schemas.microsoft.com/winfx/2006/xaml"          Title = "WPF InputBindings KeyBindings Example"  Height = "400"  Width = "400"  Focusable = "True" >      < Window.InputBindings >          < KeyBinding  Key = "C"  Modifiers = "Control"  Command ="{ Binding  CopyCommand } "  />          < KeyBinding  Key = "V"  Modifiers = "Control"  Command ="{ Binding  PasteCommand } "  />      </ Win

WPF: How to Style Horizontal GridSplitter

Image
< Window  x : Class = "HorizontalGridSplitterExample"          xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns : x = "http://schemas.microsoft.com/winfx/2006/xaml"          Title = "HorizontalGridSplitter Example"  Height = "300"  Width = "300" >      < Window.Resources >                   < Style  x : Key = "GridSplitterHorizontalGripStyle"  TargetType ="{ x : Type  GridSplitter } " >              < Setter  Property = "HorizontalAlignment"  Value = "Stretch"  />              < Setter  Property = "FocusVisualStyle"  Value ="{ x : Null } "  />              < Setter  Property = "Cursor"  Value = "SizeNS"  />              < Setter  Property = "FocusVisualStyle"  Value ="{ x : Null } "  />              < Setter  Property = "Backgr

WPF: How to Style Vertical GridSplitter

Image
< Window  x : Class = "VerticalGridSplitterExample"          xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns : x = "http://schemas.microsoft.com/winfx/2006/xaml"  Title = "VerticalGridSplitter Example"          Height = "300"  Width = "300" >      < Window.Resources >                   < Style  x : Key = "GridSplitterVerticalGripStyle"  TargetType ="{ x : Type  GridSplitter } " >              < Setter  Property = "VerticalAlignment"  Value = "Stretch"  />              < Setter  Property = "FocusVisualStyle"  Value ="{ x : Null } "  />              < Setter  Property = "Cursor"  Value = "SizeWE"  />              < Setter  Property = "FocusVisualStyle"  Value ="{ x : Null } "  />              < Setter  Property = "Background"