WPF – Windows Presentation foundation is graphical subsystem for rendering user interface. WPF was initially released as a part of .NET Framework 3.0. It relies by the use of DirectX.
WPF employs XAML, an XML-based language which is deployed as standalone desktop programs or hosted as an embedded object in a website. Windows form application, WPF applications can be designed by dragging the controls from the toolbox to design surface. It have a designer, Properties window & the toolbox from which you can design the windows form or application.
Let’s take an example to create a WPF application.
- Create a WPF application.
- Toggle between code view and designer view.
- Change the WPF Window’s properties.
- Use the XAML editor.
- Use the controls to fire an event.
Now I will explain you step by step.
- Open the visual studio from your system.
- Click on new project to create a project.
- Go to Windows-WPF application and change the file name like “Hello World WPF”.
- Go to view menu at the top of window and select toolbox and in left side of window toolbox will appear.
- Select any control from toolbox- like select a Button and textbox from toolbox by dragging it in window showing in your window.
- Select view in menu and click on properties window and it will appear on right side of window.
- Change the property of Button and Textbox from properties window by selecting individually-like Height, Width,
- After changing the property select on event which is situated just next to property on right side.
- Select Button in XAML and create an event by typing “Click”, select it and Select new event handler.
- Select Button and do right click and open “View code”. And write code in it – TextBox.Text=”Hello World”.
- After writing the code press F6 to build the solution.
- After your solution is build press F5 to start debugging. New window will open, click on Button and it will show “Hello World” in textbox.
So it’s too easy to create a WPF application using C# in visual studio. You can create this by using any control from toolbox and changing its properties and by firing any event from properties.