Saturday, January 18, 2014

PropertyDescriptor in WPF

It provides an abstraction of a property on a class.A description of a property consists of a name,its attributes,the components class associated with and the types of property.It provides a mechanism to listen to property changed events of the owner class of the actual property has INotifyPropertyChanged implemented.
It provides following properties and method
1.       Converter-It contains the TypeConverter for this property
2.       IsLocalizable-It indicates whether the property can be localized
3.       GetEditor-It returns an editor of the specified type.
It also provides following abstract properties and methods
1.       ComponentType
2.       IsReadOnly
3.       PropertyType
4.       CanResetValue
5.       GetValue
6.       ResetValue

Keyboard Attached Event in WPF

There is one namespaces named System.Windows.Input where keyboard class is defined.
Keyboard class represents the keyboard device which provides keyboard related events, method and properties that provides information about the state of the keyboard.Each of the events that keyboard defines is an attached event.
In order to receive keyboard input, the element must be Focusable.Most UIElement derived objects are Focusable and if not then set the Focusable property on the base element to true.
Some useful events KeyUp, KeyDown, PreviewKeyUp, PreviewKeyDown, GotkeyboardFocus and LostKeyboardFocus are attached events of keyboard class.

KeyUp: This event occurs when a key on the keyboard is released.
KeyDown: This event occurs when a key is pressed on the keyboard.
Preview KeyUp: This is a tunneling event corresponding to KeyUp event.
Preview KeyDown: This is a tunneling event corresponding to KeyDown event.
GotkeyboardFocus: This event occurs when an element receives keyboard focus.
LostkeyboardFocus: This event occurs when an element loses keyboard focus.

KeyboardEventExample1.xaml




KeyboardEventExample1.xaml.cs
















UI Display:
After Pressing F5, GotkeyboardFocus event get fired as shown below when we click in TextBox and hence Text’s Background color get changed to Green.












After losing focus on TextBox, LostkeyboardFocus event get fired when we click or move cursor to other window and Text’s Background color get changed to Red.












Notes:
1.       There can be only one element with keyboard focus on the entire desktop.
2.       Keyboard focus refers to the object that is receiving keyboard input.
3.       For StackPanel and Canvas, the default value of Focusable property is false.

Friday, January 17, 2014

IDataErrorInfo in WPF

IDataErrorInfo
It provides the functionality to provide a custom error information that a user interface can bind to  control.It facilitates an error message indicating what is wrong with the object.
It has two properties that expose the functionality of IDataErrorInfo interface.
1.      Error-It gets an error message indicating what is wrong with the object.
2.      Item-It gets an error message for the property with the given name.
It is present in System.ComponentModel namespace.

ListBox Example2 in WPF

ListBoxExample2.xaml









UI Display:
After pressing F5,











Now select any item in the listBox collection.After selecting anyone,we can get the number of characters in the item selected in the mentioned label control..

SliderExample1 in WPF

SliderExample1.xaml



UI Display:
After pressing F5,







Now,if we slide the slider left or right ,we can see the output as below.

GradientBrush Example1 in WPF

LinearGradientBrush
GradientBrushExample1.xaml











UI Display:
After pressing F5,











RadialGradientBrush
GradientBrushExample1.xaml











UI Display:
After pressing F5,




ScrollBar Example1 in WPF

ScrollbarExample1.xaml



UI Display
After pressing F5,













As scroll slides left or right, the value of instant change will decrease or increase.

Thursday, January 16, 2014

TextSearch Example in WPF

TextSearch
It identifies each item in a control collection.There are two properties of TextSearch as TextPath and Text.We use these as TextSearch.TextPath =” ” and TextSearch.Text=” ” respectively but serve the same purpose only way of syntaxing is different.We use this property on a control that contains a collection of items.

Here we will use a comboBox that contains images as items instead of text.Now we set IsEditable property of comboBox to true so that whenever image selected,the corresponding text could be displayed.

TextSearchExample1.xaml
1.First method





2.Second Method





UI Display:
After pressing F5











Now click on dropdown icon, we can see the collection of images in comboBox.





Now click on any image (here we clicked on Lighthouse).












We can see the text LightHouse in comboBox .

ProgressBar Example 2 in WPF

Sometimes expressing the progressing of progress bar in a fraction is not appropriate or efficient since we don’t know how long it will take. 
In this case, the indeterminate progress bar can be used efficiently, where an animation lets the user know that something is happening, while indicating that the running time can't be determined.
For this, we have to set the property IsIndeterminate of control ProgressBar to true.

ProgressBarExample2.xaml
UI Display:

Progressbar Example1 in WPF

ProgressBarExample1.xaml






UI Display:











After Pressing F5,We can see the progress of bar.











Notes:
The RepeatBehavior property of a Timeline controls states about how many times an animation repeats its simple duration. By using RepeatBehavior, we can specify a Timeline repeats for a certain number of times (an iteration count) or for a specified time period.
By default, timelines have a repeat count of 1.0, which means they play one time and do not repeat.If  we  set the RepeatBehaviorproperty of a Timeline to Forever, the timeline repeats indefinitely.

Copyright © Codingnodes,2014.All Rights Reserved.