Advanced WPF Interview Questions and Answers for Freshers - 4

Question: 16

What do you understand by WPF commands?

The commands work as a mediator between the user and the application.

Commands and event handlers are different from each other, as commands separate the action from its logic.

Due to this, multiple elements can call the same command logic, which can be customized for different targets.

A command source calls the command and executes it on a command target.

The WPF commands implement the ICommand interface and the command sources implement the ICommand Source interface.

If you do not specify the command source, then it uses the keyboard focus to become the command target.

For example, if the Menu Item control has Textbox and a Password Box controls and it invokes the paste command without specifying the command target, then the target of the Paste command can be either of the two controls depending on which control has the keyboard focus.

Question: 17

What are markup extensions?

A markup extension is a means of setting the value of a property to an object reference rather than a string or numeric value. Markup extensions can be used to set a property value such that the value is based on another element or object. With markup extensions, the assignment of property values can be delayed until run time. Some of the common markup extensions in WPF 4.0 are

Binding – Allows data bound values for a property

StaticResource – Allows an existing WPF resource to be used as the property value

DynamicResource – Allows a WPF resource to be used as the property value only at run time

TemplateBinding – Allows the property value in the control template of an element to be used as the property value.

All the markup extensions are objects of the classes that inherit the System.Windows.Markup.MarkupExtension class.

Related Questions