Thursday, January 5, 2012

WPF Interview Questions and Answers


Ask in All WPF Interview 

Visit for Important WPF Questions and Answers

www.code-sample.com/2013/08/wpf-interview-questions-and-answers.html


WPF stands for Windows Presentation Foundation. It is an application programming Interface for developing rich UI on Windows. WPF is introduced in .NET 3.0. By the use of WPF we can create two and three dimensional graphics, animations etc.

What is XAML and how it is related to WPF?
XAML is a new mark up language which is used for defining UI elements and its relationships with other UI elements. The XAML is introduced by WPF in .NET 3.0 WPF uses XAML for UI design.

Does XAML file compiled or Parsed?
By default XAML files are compiled, But we do have options to let it be parsed.

What is the root namespace used for Animations and 3D rendering in WPF?
System.Windows.Media namespace.

What are the names of main assemblies used by WPF?
a)WindowsBase
b)PresentationCore
c)PresentationFoundation

Describe the types of documents supported by WPF?
There are two kinds of document supported by WPF
a)Flow format:Flow format document adjusts as per screen size and resolution
b)Fixed Format:Fixed Format document does not adjust as per screen size and resolution

What namespaces are needed to host a WPF control in Windows form application?
The following namespaces needs to be referenced:
a)PresentationCore.dll
b)PresentationFramework.dll
c)UIAutomationProvider.dll
d)UIAutomationTypes.dll
e)WindowsBase.dll

What is dependency property?
 A property that is support by the WPF property system is known as a dependency property.
Example:
<StackPanel Canvas.Top="50" Canvas.Left="50"  DataContext="{Binding Source={StaticResource XmlTeamsSource}}">
  <Button Height=”30” width=”80” Content="{Binding XPath=Team/@TeamName}" Background="Red"  Style="{StaticResource GreenButtonStyle}"/>
</StackPanel>
Here Height, width, Baground etc are regular property but DataContext, Style, ‘Canves.Lef’t, ‘Canves .right ‘are the dependency on this example, that is call dependency property. I thing, all WPF binding control are dependency property. 

What is routed event in wpf?
A routed event is a CLR event that is support by an instance of the Routed Event class and is processed by the Windows Presentation Foundation (WPF) event system.
For example: Event bubbling is good concept routed event.
<StackPanel Background="LightGray" Orientation="Horizontal" Button.Click="CommonClickHandler">  
    <Button Name="YesButton" Width="Auto" >Yes</Button>
</StackPanel> 

What does mean "x:" prefix in xaml code?
It is an xml namespace that usually refers to the xaml namespace.
Example:
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

What is XBAP Stands?
XBAP Stands for XAML Browser application.

What is a .baml file?
An XAML file is compiled in .net, become a file with a .baml extension, which stand for binary XAML.

Types of window in wpf?
Normal window
Navigate window
Page Window

What is dispatcher Object?
It is the main of all WPF controls which Take care UI Thread.

What are the method in DependencyObject in WPF?
ClearValue
SetValue
GetValue

What types of control in wpf?
Content control
Layout control
Item control

Can you create Window service in WPF?
No! , It use for UI, we create a cervices using c# or other language.

What is XBAP?
XBAP is stand for XAML Browser Application which is a new Windows technology used for creating Rich Internet Applications.
While windows applications are normally compiled to an .exe file, browser applications are compiled to an extension .xbap and can be run inside Internet Explorer.
Xbap applications are run within a security sandbox to prevent untrusted applications from controlling local system resources. (e.gdeleting local files)

What is the differenece between System.Windows.dll and System.Windows.Browser.dll?
1)System.Windows.dll:-This Assembly includes many of the classes for building Silverlight user interfaces,including basic elements,Shapes and Brushes,classes that support animation and databinding,and the version of the FileOpenDialog that works with isolated storage.
2)System.Windows.Browser.dll:-This Assembly contains classes for interacting with HTML Elements.

Name the Classes that contains arbitrary content in WPF?
1)ContentControl:- A single arbitrary object.
2)HeaderedContentControl:- A header and a single item, both of which are arbitrary objects.
3)ItemsControl:- A collection of arbitrary objects.
4)HeaderedItemsControl:- A header and a collection of items, all of which are arbitrary objects.

Name the Events that are implemented by NavigationService?
1)Navigating:- Occurs when a new navigation is requested. Can be used to cancel the navigation.
2)NavigationProgress:- Occurs periodically during a download to provide navigation progress information.
3)Navigated:- Occurs when the page has been located and downloaded.
4)NavigationStopped:- Occurs when the navigation is stopped (by calling StopLoading), or when a new navigation is requested while a current navigation is in progress.
5)NavigationFailed:- Occurs when an error is raised while navigating to the requested content.
6)LoadCompleted:- Occurs when content that was navigated to is loaded and parsed, and has begun rendering.
7)FragmentNavigation:- Occurs when navigation to a content fragment begins, which happens:
a)Immediately, if the desired fragment is in the current content.
b)After the source content has been loaded, if the desired fragment is in different content.

What is the default Orientation of Stack Panel?
The Default Orientation of Stack Panel is 'Vertical'.

What are the major subsystems of the Windows Presentation Foundation?
1) Object
2) Threading.DispatcherObject
3) Windows.DependancyObject
4) Windows.Media.Visuals
5) Windows.UIElements
6) Windows.FrameworkElement
7) Windows.Controls.Control

In Which NameSpace you will find a 'Popup' and 'Thumb' control in WPF?
In 'system.windows.controls.primitives' namespace

Name Some Methods of MediaElement in WPF?
MediaElement has the following methods :-
1)Play:-Plays media from the current position.
2)Stop:-Stops and resets media to be played from the beginning.
3)Pause:-Pauses media at the current position.
4)Close:-Closes the media.

How to Set Window Title Bar Name at RunTime in WPF?
this.Title="TitleName";
In Which of the Following Definitions element you will find a 'Width' and 'Height' of a Grid(TAG)
1)<Grid.RowDefinitions >
2)<Grid.ColumnDefinitions>
In <Grid.RowDefinitions > you will find a 'Height'
eg: <Grid.RowDefinitions >
<RowDefinition Height="50" />
</Grid.RowDefinitions>
In <Grid.ColumnDefinitions> you will find a 'Width'
eg:<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
</Grid.ColumnDefinitions>

What are the Features of WPF?
The Features of WPF are:-
1)Device Independent Pixel (DPI).
2)Built-In Support for Graphics and Animation.
3)Redefine Styles and Control Templates.
4)Resource based Approach for every control.
5)New Property System & Binding Capabilities.

Name the Layout Panels of WPF?
These are the five most layout panels of WPF:-
1)Grid Panel
2)Stack Panel
3)Dock Panel
4)Wrap Panel
5)Canvas Panel

What are the difference between CustomControls and UserControls in WPF?
CustomControl (Extending an existing control):-
1)Extends an existing control with additional features.
2)Consists of a code file and a default style in Themes/Generic.xaml.
3)Can be styled/templated.
4)The best approach to build a control library.
UserControl (Composition):
1)Composes multiple existing controls into a reusable "group".
2)Consists of a XAML and a code behind file.
3)Cannot be styled/templated.
4)Derives from UserControl.

What are the Advantages of XAML?
1)XAML code is short and clear to read.
2)Separation of designer code and logic.
3)Graphical design tools like Expression Blend require XAML as source.
4)The separation of XAML and UI logic allows it to clearly separate the roles of designer and developer.

Which class of the WPF is the base class of all the user-interactive elements?
Control class is the base class of all the user-interactive elements in WPF.


What is Markup Extensions?
The most common markup extensions used in WPF application programming are Binding, used for data binding expressions, and the resource references StaticResource and DynamicResource.
<StackPanel>
  <Border Style="{StaticResource PageBackground}"></Border>
</StackPanel>

What is type convertor?
In the section, it was stated that the attribute value must be able to be set by a string. The basic, native handling of how strings are converted into other object types or primitive values is based on the String type itself, in addition to native processing for certain types such as DateTime or Uri. But many WPF types or members of those types extend the basic string attribute processing behavior, in such a way that instances of more complex object types can be specified as strings and attributes.

About The X: prefix?
The prefix x: was used to map the XAML namespace http://schemas.microsoft.com/winfx/2006/xaml, which is the dedicated XAML namespace that supports XAML language constructs. This x: prefix is used for mapping this XAML namespace in the templates for projects.
x:Key: Sets a unique key for each resource in a ResourceDictionary.
Example:
 <object x:Key="stringKeyValue".../>
x:Class: Specifies the CLR namespace and class name for the class that provides code-behind for a XAML page.
Example:
<object x:Class="namespace.classname".../>
x:Name: Specifies a run-time object name for the instance that exists in run-time code after an object element is processed.
Example:
<object x:Name="XAMLNameValue".../>
x:Static: Enables a reference that returns a static value that is not otherwise a XAML-compatible property.
Example:
<object property="{x:Static prefix:typeName.staticMemberName}" .../>
x:Type: Constructs a Type reference based on a type name.
Example:
<object property="{x:Type prefix:typeNameValue}" .../>


This example shows you how to create a simple Binding.
In this example, you have a Person object with a string property named PersonName. The Person object is defined in the namespace called SDKSample.
The following example instantiates the Person object with a PersonName property value of Anil. This is done in the Resources section and assigned an x:Key.
XAML
<Window  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  xmlns:ak="clr-namespace:SDKSample"
  Title="Simple Data Binding Sample">
  <Window.Resources>
    <ak:Person x:Key="myDataSource" PersonName="Anil"/>
  </Window.Resources>
  <Grid>
   <TextBlock Text="{Binding Path=PersonName, Source={StaticResource myDataSource}}"/>
  </Grid>
</Window>
As a result, the TextBlock appears with the value "Anil".
MultiBinding:
 </TextBlock >


Tuesday, January 3, 2012

HTML 5


Download the setup files:



First Step:  
First we put the file “HTML_5.xsd” on the path “C:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\schemas\html”.
Second Step:
Run the file “HTML-5-Schema-Reg-x64” & “HTML-5-Schema-Reg-x64-VWD” for 64bit OS.
OR
Run the file “HTML-5-Schema-Reg-x86” & “HTML-5-Schema-Reg-x86-VWD” for 32bit OS.
Third Step:
Restart the VS2008/2010 application.  And write the code in “.aspx” file for demo test.

Example code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>HTML5 test</title>
</head>
<body>  
         <form id="mainform" runat="server">
         <asp:Label ID="Label1" runat="server" Text="Label"> .Net Control test</asp:Label>
          <asp:TextBox ID="name" required runat="server" placeholder="Fill in your name!" title="Enter your name!"></asp:TextBox><br />
                 
           <label>Name:</label>   
           <input id="name" name="name" type="text" required placeholder="Fill in your name!"  title="Enter your name!" />  <br />

           <label>Age:</label>
           <input  id="age" name="age" title="Enter your age!"  type="number" required  min="18" max="88" value="18"/><br />
               
          <label>Email:</label> 
            <input  id="email" name="email" type="email" required placeholder="anil.singh@droisys.com" title="Enter an email!" /> <br />
    
            <label>Date:</label> 
            <input  id="date" name="date" type="date" required  title="Enter a date!" placeholder="10/03/1984" /> <br />
                    
           <label>Phone No:</label> 
           <input id="phone" name="phone" type="tel" pattern="\d\d\ \d\d\d\d\d\d\d\d\d\d" required placeholder="91 9015519979" title="Enter a Cell number!" /> <br />

           <label>Site URL:</label>   
            <input id="site"  name="site" type="url" required placeholder="http://www.droisys.com" title="Enter the url of your site!" /><br />
               
           <input  id="submit" name="submit" type="submit" value="Send Data" />
    
      </form>
   
</body>
</html>



Descriptions on HTML5

1) Launch Visual Studio and create an empty website.

2) Add a simple html item to your site. This is the mark up for the html form

3) View your form in the browser. This is a typical form. We will have a name field,an email field, an age field,a date field, a site field, a phone field and a submit button.
Later on I will add a "range" field called Priority.

4) Now let's upgrade the form to HTML 5.Let's say that we want to require for every input field to have some data. We could do that with custom JavaScript code, or using the built in web server validation controls.
I have provided some examples on how to use validation with all the ways mentioned above. You can find them here, here and here.

In HTML 5 the only thing I must do is to add the required attribute.

Have a look at the code below for the name field

 <input id="name" name="name" type="text" required />

Make sure you do that for all the input fields you require to have a value.

So without any JavaScript I have validation out of the box. How cool is that. View your page with Firefox or Chrome and see the result for yourself.
Now we can add some watermark effect very easily to our page. I have provided in this blog another example on how to do that with JQuery. Have a look here if you want.
We can do that in HTML 5 without any JavaScript code simply by adding the placeholder attribute to the input field.

<input id="name" name="name" type="text" required placeholder="Fill in your name!"  title="Enter your name!" />

Make sure you do that for the rest of the input fields you think it is appropriate.
In the Age field we need to make sure that only positive numbers from 18-88 are allowed.
We can do that by changing the input type to number and setting the min and max values appropriately. (This will not work in Firefox)

<input  id="age" name="age" title="Enter your age!"  type="number" required  min="18" max="88" value="18"/>
Another validation we want to perform is to have a valid email. We can do that by changing the input type to email.
 The code looks like that

<input  id="email" name="email" type="email" required placeholder="anil.singh@droisys.com" title="Enter an email!" />

View it in the browser and see for yourself. Have a look at the Page Source. We have pure HTML that our users and search engines will love.

Another validation we want to perform is to have a valid date. We can do that by changing the input type to date. This will provide us with a datetime picker control.

This will not work in Firefox and Chrome.
The code looks like that

<input  id="date" name="date" type="date" required  title="Enter a date!" placeholder="10/03/1984" />

View it in the browser and see for yourself. Have a look at the Page Source. We have pure HTML that our users and search engines will love.

Now we need to add some sort of validation for the Site field. I just change the type from text to url.

<input id="site"  name="site" type="url" required placeholder="http://www.droisys.com" title="Enter the url of your site!" />

Then we need to have some sort of validation for the telephone field, so the define a new type=”tel” attribute and a new pattern attribute

<input id="phone" name="phone" type="tel" pattern="\d\d\ \d\d\d\d\d\d\d\d\d\d" required placeholder="91 9015519979" title="Enter a Cell number!" />

I have added another field with a new field Priority that is of type "range", that give us a slider effect.

  <input id="priority" name="priority" title="from 0 to 5" type="range" min="0" max="5" value="2" />

If we need to set the focus on the first field, we just add the autofocus attribute.

<input id="site"  name="site" type="url" required placeholder="http://www.droisys.com" title="Enter the url of your site!" autofocus="on"/>

 If we do not the browser to suggest values to enter in the field, then we can turn it off by using the auto complete attribute to off.
I am showing that only for the first field.

<input id="site"  name="site" type="url" required placeholder="http://www.droisys.com" title="Enter the url of your site!" autofocus="off"/>

You could do that for all the fields you do not want the auto-complete feature on.
Well, I am going to post now the complete markup.

<body>  
         <form id="mainform" runat="server">
         <asp:Label ID="Label1" runat="server" Text="Label"> .net Control</asp:Label>
          <asp:TextBox ID="name" required runat="server" placeholder="Fill in your name!" title="Enter your name!"></asp:TextBox><br />
                 
           <label>Name:</label>   
           <input id="name" name="name" type="text" required placeholder="Fill in your name!"  title="Enter your name!" />  <br />

           <label>Age:</label>
           <input  id="age" name="age" title="Enter your age!"  type="number" required  min="18" max="88" value="18"/><br />
               
          <label>Email:</label> 
            <input  id="email" name="email" type="email" required placeholder="anil.singh@droisys.com" title="Enter an email!" /> <br />
    
            <label>Date:</label> 
            <input  id="date" name="date" type="date" required  title="Enter a date!" placeholder="10/03/1984" /> <br />
                    
           <label>Phone No:</label> 
           <input id="phone" name="phone" type="tel" pattern="\d\d\ \d\d\d\d\d\d\d\d\d\d" required placeholder="91 9015519979" title="Enter a Cell number!" /> <br />

           <label>Site URL:</label>   
            <input id="site"  name="site" type="url" required placeholder="http://www.droisys.com" title="Enter the url of your site!" autofocus="off"/><br />
          
 
               
           <input  id="submit" name="submit" type="submit" value="Send Data" />
    
      </form>
   
</body>


All HTML 5 Tags:
<!--...--> Tag
Example:
An HTML comment:
<!--This is a comment. Comments are not displayed in the UI Screen!-->
<p>This is a paragraph.</p>


<source> Tag:
Example:
The <source> tag is used to specify multiple media resources for media elements, such as <video> and <audio>.
The <source> tag allows you to specify alternative video/audio files which the browser may choose from, based on its media type or codec support.
An audio player with two source files.
The browser should choose which file (if any) it has support for:
 <audio controls="controls" loop="loop">             
      ource src="images/SleepAway.mp3" type="audio/mp3"  />               
 </audio>  

Autoplay video & Autoplay Audio:

<section id="intro">
    <h2 class="intro">Autoplay video </h2>
    <video width="320" height="240" controls="controls" autoplay="autoplay">
                  <source src="images/movie.mp4" type="video/mp4" />                
             </video>
             <h2 class="intro">Autoplay Audio </h2>              
        <audio controls="controls">              
                  <source src="images/SleepAway.mp3" type="audio/mp3" />                
             </audio>           
    </section>  

Attributes of video & Audio:

Attribute
Value
Description
autoplay
autoplay
Specifies that the audio will start playing as soon as it is ready
controls
controls
Specifies that audio controls should be displayed (such as a play/pause button etc).
loop
loop
Specifies that the audio will start over again, every time it is finished
preload
auto
metadata
none
Specifies if and how the author thinks the audio should be loaded when the page loads
src
URL
Specifies the URL of the audio file


<progress> Tag:  
The <progress> tag represents the progress of a task.
Example:
<html>
<body>
Downloading progress:
<progress value="22" max="100">
</progress>
</body>
</html>


<colgroup> Tag: 
Set the background color of the three columns with the <colgroup> and <col> tags.
Example:
<table>
  <colgroup>
    <col span="2" style="background-color:red" />
    <col style="background-color:yellow" />
  </colgroup>
  <tr>
                 <th>Name</th>
                 <th>Title</th>
                 <th>Price</th>
  </tr>
  <tr>
                <td>A Kumar</td>
                 <td>first HTML5</td>
                 <td>32000 Rs.</td>
  </tr>
</table

<option> Tag:
A drop-down list with four options.
Example:
<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

<dl> Tag:
Example:
The <dl> tag defines a definition list.

The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes the item in the list).

<dl>
  <dt>.net Book</dt>
     <dd>VS2011</dd>
  <dt>>SQL Book </dt>
     <dd>SQL Server 2011</dd>
</dl>

<footer> Tag:
Example:
The <footer> tag defines footer for a document or section.
Footer typically contains the author of the document, copyright information, links to terms of use, contact information, etc.
<footer> Copyright 2012-2060.</footer>

<fieldset> Tag:
Example:
The <fieldset> tag is used to group related elements in a form.
The <fieldset> tag draws a box around the related elements.
<fieldset>
    <legend>Information:</legend>
    Name: <input type="text" /><br />
    Email: <input type="text" /><br />
    Date of birth: <input type="text" />
</fieldset>

<form> Tag:

Example:
The <form> tag is used to create an HTML form for user input.
An HTML form with two input fields and one submit button:
<form action="Test_form.aspx">
  First name: <input type="text" name="fname" value="Welcome!" /><br />
  Last name:<input type="text" name="lname" value="Hero!" /><br />
  <input type="submit" value="Submit" />
</form>


<menu> Tag:
Example:
A toolbar with two menu buttons on it ("Headermenu"), each of which has a dropdown menu with a series of options:

<menu type="toolbar">
<li>
<menu label=" Headermenu ">
<button type="button" >Home...</button>
<button type="button" >About...</button>
<button type="button" >Contact…</button>
</menu>
</li>
</menu>

<meter> Tag:
Example:
The <meter> tag defines a scalar measurement within a known range, or a fractional value. This is also known as a gauge.
Use the meter element to measure data within a given range (a gauge):
<meter value="2" min="0" max="10">5 out of 10</meter><br />
<meter value="0.7">70%</meter>
Note: The <meter> tag should not be used to indicate progress (as in a progress bar). For progress bars, use the <progress> tag.


<s> Tag:
Example:
The <s> tag specifies text that is no longer correct, accurate or relevant.
The <s> tag should not be used to define replaced or deleted text, use the <del> tag to define replaced or deleted text.
<p>
<s>My car is blue.</s>
</p>
<p>My new car is silver.</p>


Thanks,
Anil Singh