How to Change XAML Auto-formatting Options in WPF designer

XAML view provides an auto-formatting feature, which enables uniform spacing and line break structure for XAML markup. To auto-format your XAML markup, press CTRL+KD when XAML view is open.

following are the steps for changing xaml auto-formatting options:

1. goto Tools menu and select Options.
2. Expand the Text Editor item in the Options dialog box.
3. Expand XAML.
4. Expand Formatting.
5. Under Formatting, select General or Spacing, you can see variousformatting options
6. Set the formatting options according to your preferences.

How to create simple event handler in WPF

Suppose you want to create simple event handler of any control. means you want if you click on Button control then some specific task should be performed, for it we use event handler and in this case we use clixk event of the button control.
Here articles describe ways to create simple event handlers in the WPF Designer.

How to create a default event handler:

you can create default event handler just by double click on the control.after that the code-behind file is opened and the cursor is positioned in the default event handler.

How to create an event handler in XAML
following are the steps for creating event handler in xaml.(we are using button click event on here)
1. locate button element in xaml.
2. Write the event name that you want to handle in the start tag for the element. Suppose if you want to use Click event of the button then you can write Click then an IntelliSense list appears with the available events. you can choose from this list.

The following XAML specifies a Click event handler for a Button control.

<Window x:Class="Window1"
    Title="Window1" Height="252" Width="300" Name="Window1">
    <Grid  Height="221" Width="300">
        <Button Name="Button1"  Width="75" HorizontalAlignment="Left"

3. if you want to use this event in code behind file then you can right-click the event or event handler name and select the Navigate to Event Handler option in xaml view, then The code-behind file is opened and the cursor is positioned in the selected event handler. The following code shows example event handlers.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
End Sub

How to create an event handler by using the Code Editor drop-down lists
1. Open the Class Name drop-down list In the Code Editor.
2. Select the control or type that you want to create an event handler for.
3. Open the Method Name drop-down list.
4. Select the event that you want create an event handler for.
An event handler is created and the cursor is positioned in the event handler.

How to start a New WPF Application Project in visual studio 2010

1. Start Visual Studio 2010.
2. Goto File menu, select new New, and then select Project and then The New Project dialog box appears.
3. Expand Visual Basic or Visual C#, and then select Windows In the Installed Templates Pane.
4. Select the WPF Application template, in the middle pane.

5. Select the target framework from the drop-down list.
6. Specify a name for the project in the Name text box
7. Click OK.

project will be display like as

The WPF Designer is very similar to the Windows Forms Designer.  

The WPF Designer has several windows for displaying and editing XAML documents. Such as Design view,XAML view and toolbox etc(you can see in picture).

Design View:  provides a visual design surface for building your WPF controls and applications. It shows a rendered representation of the XAML currently in XAML view.

XAML View: this provides us to edit or create xaml document,design view is the mirror of the xaml view mean you can see all work that is done with xaml in design view.

Toolbox View: very similar to the windows form toolbox.

How to add Custom Context Menu with a TextBox in WPF

In this article i am describing about how to add the custom context menu for the your textbox control in your WPF project. Context menu in the textbox is very common functionality, generally we frequently need to textbox that can perform cut and copy from clipboard operation. Continue reading “How to add Custom Context Menu with a TextBox in WPF”

How to set background image to a textbox in wpf application

The following example demonstrates that how to set background image to a textbox in wpf application.

<Window x:Class=”Window1″



    Title=”Window1″ Height=”300″ Width=”500″>


    <TextBox Height=”30″ Width=”237″ MaxLength=”100″

             Name=”tbMultiLine”   >


            <ImageBrush ImageSource=”E:\AuthorCode\Images\s.gif” AlignmentX=”Left” Stretch=”None” />






  Continue reading “How to set background image to a textbox in wpf application”

Textbox in Wpf

Common use of a Textbox is editing unformatted text in a form. suppose if you want to show simple data entry form like client contact form in which you need to enter some detail about client such as phone number, Name, address etc ., then we can use textbox control.

In this article we will discuss how to use textbox in XAML.

Continue reading “Textbox in Wpf”