Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts
Saturday, February 8, 2014
Sunday, January 19, 2014
ContextMenu Example in WPF
Menu
A Menu is
normally we see at the top of the window.Each of them in those menus are
MenuItems.
ContextMenu
It is similar to
Menu that pops ups when we right click on something.It is contexted to what is
clicked.
Example of
ContextMenu
ContextMenuExample1.xaml
UI Display:
After right click on RichTextBox,we can see the Context Menu.
Difference between Grid, StackPanel, WrapPanel, DockPanel and Canvas in WPF
Grid
Grid is the
default container where we can arrange the elements in table format.
StackPanel
By using
StackPanel we can arrange the elements vertically or horizontally.We can
arrange child elements in a panel without affecting the size of the lements.
WrapPanel
WrapPanel is
same as StackPanel but it wraps the elements accordingly to size of the form. The
control in Wrap Panel is shifted to the next line automatically if the form
size is getting changed.
DockPanel
DockPanel is
used to place the control in exact location like as Left, Right, Top and Bottom.
If we not specify any position then control will occupy entire space on the container.
If we not specify any position then control will occupy entire space on the container.
Canvas
Canvas is used
to place the control by specifying the position in pixel format.We can use Canvas.Left,
Canvas.Right,Canvas.Bottom and Canvas.Top.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.
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 .
Subscribe to:
Posts (Atom)

























