Thursday, July 28, 2016

Abstract Class VS Interface in C#

An interface is more supple from the client's perspective:
any class can implement as many interfaces as it wants to. Unfortunately, an interface is more rigid from the developer's perspective: it can't be easily changed and it does not support any kind of reusability.

An abstract class is supple from the developer's perspective:
it supports reusability, it supports encapsulation, it can be extended easily without breaking existing clients.
With all that said, we can conclude the interesting rule of thumb: use abstract classes for building internal APIs and use interfaces for providing external points of extension.

Monday, July 18, 2016

ICommand WPF


<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button Command="{Binding ClickCommand}" Width="100" Height="100" Content="wefwfwef"/>
</Grid>

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new ViewModelBase();
    }
}

public class ViewModelBase
{
    public ViewModelBase()
    {
        _canExecute = true;
    }
    private ICommand _clickCommand;
    public ICommand ClickCommand
    {
        get
        {
            return _clickCommand ?? (_clickCommand = new CommandHandler(() => MyAction(), _canExecute));
        }
    }
    private bool _canExecute;
    public void MyAction()
    {

    }
}
public class CommandHandler : ICommand
{
    private Action _action;
    private bool _canExecute;
    public CommandHandler(Action action, bool canExecute)
    {
        _action = action;
        _canExecute = canExecute;
    }

    public bool CanExecute(object parameter)
    {
        return _canExecute;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        _action();
    }
}

Wednesday, July 13, 2016

Triggers in WPF


There are three types of Triggers available.

  • Event Trigger
Event Trigger used perform action when RoutedEvent of FrameworkElement raise.Event Trigger generally used to perform some animation on control (like : colorAnimation, doubleAnumation using KeyFrame etc.)  Let's first understand Storyboard and Animation.

Storyboard Storyboard is used to provide animation to the properties of the UIElement. Storyboard has TargetName andTargetProperty  attached properties for apply animation to the Control (TargetName) and Control Property (TargetProperty).

  • Property Trigger 

Property Trigger Executes Collections of Setters, when UIElements property value changes. To create a trigger on any controls, you have to set trigger in style of the control.


MultiTrigger MultiTrigger is used to set action on Multiple Property change. It will execute when all condition are satisfy within MulitTrigger.Condition.

 

  • Data Trigger        

 As the name suggest, DataTrigger applies property value to perform action on Data that Binding to the UIElement. DataTrigger allows to set property value when Binding Data matches specified condition.


MultiDataTrigger MultiDataTrigger is same as DataTrigger in addition property value applied on multiple condition is matches.

 

Ref this link for more details

http://www.codeproject.com/Tips/522041/Triggers-in-WPF

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code