.Net Interview Questions and Answers

Search:

What are resources in WPF? (C# WPF Interview questions with answers)

By : Shiv Prasad Koirala | Jan 3rd, 2014 | Views : 8417 | Comments : 0 Bookmark and Share

Resources are objects referred in WPF XAML. In C# code when we create an object we do the following three steps:-


using CustomerNameSpace; // import the namespace.

Customer obj = new Customer(); // Create object of the class

Textbox1.text = obj.CustomerCode; // Bind the object with UI elements


So even in WPF XAML to define resources which are nothing but objects we need to the above 3 steps :-


  • Import namespace where the class resides: - To define namespace we need to use the "xmlns" attribute as shown in the below XAML code.


        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:custns="clr-namespace:LearnWpfResources"

        Title="MainWindow" Height="350" Width="525">


  • Create object of the class :- To create an object of the class in XAML we need to create a resource by using the resource tag as the below code. You can the object name is 'custobj".



<Window.Resources>

<custns:Customer x:Key="custobj"/>

</Window.Resources>



The above code you can map to something like this in C#


Customer custobj = new Customer();


  • Bind the object with UI objects :- Once the object is created we can then bind them using bindings like one way , two way as explained in "Explain one way, two way, one time and one way to source?".


Please see this WPF binding interview question from here http://questpond.blog.com/2013/11/11/explain-wpf-bindings-net-wpf-binding-interview-questions/


<TextBox Text="Binding CustomerCode, Mode=TwoWay, Source=StaticResource custobj}}" />


Below video explain what is WPF and how they differ from Windows form


 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi