An abstract class is a special kind of class that has no implementation. It cannot be instantiated. Its implementation logic is provided by the classes that derive from it. It can have both abstract as well as non-abstract methods.
It is not compulsory to have only abstract methods in an abstract class. We can also have an abstract class with only non-abstract methods.
Dependency property can be linked to another property such that a change in the value of one changes the other.
The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs. These other inputs might include system properties such as themes and user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements in the element tree.
Dependency properties are NOT intended to support source to data binding, this is where INotifyProperty comes in. From a pure point of view you shouldn’t use DP on a ViewModels. INotifyPropertyChanged better for exposing properties from business logic(viewmodel) to GUI(view). Continue reading →
When there are some sub tasks or series of subsystems.
In such cases we need to bother about all the subsystems or we can say we need to remember all the classes, methods and sequence of calling. So to avoid this situation, we can use Facade pattern which provides an interface to client code and hide all the subsystems.
Lets takes an example for facade design pattern. Suppose I need to turn off my Desktop. So the activities involve in this task is : 1. Save my Work and ShutDown Windows. 2. Turn off Monitor 3. Turn off UPS. So there are 3 subsystems and my program looks like: There are 3 different classes with their respective methods. Continue reading →
DataContext expects an object type where ItemsSource expects IEnumerable type objects.
DataContext is a dependency property is exposed by FrameworkElement base class,where as ItemsSource is defined by the ItemsControl class. All the descendants of FrameworkElement can utilize the DataContext property and set an object to its value. But we can only set a type of IEnumerable(or instance of class that derives from).
DataContext does not generate template, it only used to hold common data for other controls to bind. In terms of ItemsSource property, it is mainly used to generate template regardless of you set it in XAML or in the code behind.
DataContext is mainly used to hold common data that other child want to share. Thus it can be inherited by other child elements without problem. But for ItemsSource, it not used to share data in the visual tree. It is only valid for the element that defined. There is still one thing to be noted is that the child element can override the DataContext of the perent DataContext no mater directly or indirectly.
Creating a method in derived class with same signature as a method in base class is called as method overriding. Same signature means methods must have same name, same number of arguments and same type of arguments. Method overriding is possible only in derived classes, but not within the same class. When derived class needs a method with same signature as in base class, but wants to execute different code than provided by base class then method overriding will be used. To allow the derived class to override a method of the base class, C# provides two options,virtual methods and abstract methods. You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract.
If a method is not overriding the derived method, it is hiding it in the Derived class. A hiding method has to be declared using the new keyword. Continue reading →
Delegates give developers the power to make methods that can have behavior injected into them, while retaining the type safety of C#. They lend themselves well to writing highly reusable and DRY code. They are very effective when used as callbacks to various system events. Deligate is used to hookup our Event to EventHandler method. Delegates are type safe function pointers. Delegates are widely used in events declaration.