.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

how to generate the tabcontrol in code behind in WPF application

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :WPF

Hi All

 I Am new in WPF application i need to develop the application how the VS2010  solution Explorer Tree view is working when user click the particular file it open in the new tab in the same way i need to develope to my application.

What i am done is i have the menu item like



when user click the menu item  dynamically add the tab item with menu name . my problem is when i select the first menu item its working fine . when i am trying to click the next menu item it show error like this

--> Element already has a logical parent. It must be detached from the old parent before it is attached to a new one.

how to fix this problem any one help me.

this is my code in code behind

TabControl item_tabs = new TabControl();
    TabItem newtab1 = new TabItem();
    private void Window_Loaded(object sender, RoutedEventArgs e)
      item_tabs = (TabControl)this.FindName("itemtab1");

    private void new_men_Click(object sender, RoutedEventArgs e)
      // TabControl item_tabs = (TabControl)this.FindName("itemtab1");
      int count = item_tabs.Items.Count;
      if (count == 0)
        string itemname = new_men.Name.ToString();
        // newtab1.Content = itemname;
        newtab1.Header = itemname;

View Complete Post

More Related Resource Links

Ho to fire the Application Error in asax from the code?


 Hi All,

I have this code in Global.asax but it not firing once an error occured:


void Application_Error(object sender, EventArgs e)



        // Get the error details

        HttpException lastErrorWrapper = Server.GetLastError() as HttpException;

        Exception lastError = lastErrorWrapper;

        if (lastErrorWrapper.InnerException != null)

        lastError = lastErrorWrapper.InnerException;



        string lastErrorTypeName = lastError.GetType().ToString();

        string lastErrorMessage = lastError.Message;

        string lastErrorStackTrace = lastError.StackTrace;



Please help me so I can call this method from any page?

Thaxxxxxxxxxxxxx a lot,



Code Reviews: Find and Fix Vulnerabilities Before Your Application Ships


Code defects can be found using many approaches, but manual code reviews stand out in terms of precision and quality. We provide some best practices for planning and executing code reviews on your own team.

M. Chmielewski, N. Clift, S. Fonrobert, and T. Ostwald

MSDN Magazine November 2007

Stay Alert: Use Managed Code To Generate A Secure Audit Trail


In today's security-conscious environments, a reliable audit trail is a valuable forensic tool The Windows Server 2003 operating system provides features that let you enable a wide range of applications to make use of auditing functionality. This article looks at auditing from the operating system perspective and describes a sample managed code implementation that will allow you to add auditing to your own server applications.

Mark Novak

MSDN Magazine October 2005

Testing: Perform Code Coverage Analysis with .NET to Ensure Thorough Application Testing


When running your tests how do you know which parts of your product code are actually executed and tested? This article presents a complete system called Fundamental Function code coverage that operates at the method level. The author gives an overview of the system so you can understand code coverage principles, explains the key parts of the underlying code, and discusses how code coverage fits into the overall product development cycle. After reading this article you will be able to perform code coverage analysis on any .NET software system.

James McCaffrey

MSDN Magazine April 2004

C# and the Web: Writing a Web Client Application with Managed Code in the Microsoft .NET Framework


When the author wanted to build a middleware Web client to connect to other applications over the Internet, he realized that the XMLHttpRequest COM object was not sufficient for his purposes. In order to build a Web client using managed code, the author had to use the HTTPWebRequest and HTTPWebResponse classes provided by the Microsoft .NET framework. These classes are used in the sample project as a substitute for the less powerful XMLHttpRequest COM object, allowing the author to build a full-featured Web client. They also take advantage of all the benefits that the CLR and managed code have to offer.

Avi Ben-Menahem

MSDN Magazine September 2001

Custom tool error: Failed to generate code for the service reference 'CompanyService'. Please che


A little background because I feel I have an out of the ordinary architecture in place and don't know if this is contributing to the problem. 

We have an existing ASP.net application that is undergoing expansion.  The new functionality is all written in Silverlight 4.  As part of that expansion I gutted all the old Linq to SQL and put Entity Framework 4 into place.  To do this I created a standard .net Class Library and added my edmx files there.  Naturally, the business entities created by this cannot be used in Silverlight.  So I created a Silverlight Class Library and added all the business entities to that Silverlight Class Library as linked files.  I changed the name space to be the same.

So I have the following assembly / namespaces

Company.Project.Dal.csproj / Company.Project.Entities (.net 4 class library)

Company.Project.Entities.csproj / Company.Project.Entities (SL4 class library)

With this architecture I was able to share my business entities with my SL enabled web services, my asp.net projects, my silverlight projects.  Really it's a beautiful thing.

Once this was done I added "message" classes to Company.Project.Dal and again shared them with the other entites using linked files.  These messages are things like MyObjectRequest; they are class

Use DB query result to generate Jquery required lines of code



I 'm gonna query database for photo records. each record include "photo path" where imagesURL  stored in string format

 I Choses my favorite Juqery plugin to show images. Plugin needs some lines of code like below.

How could I  generate these lines

$(function() {
sleep: 2,
fade: 1
}, [
{ src: 'picture1.jpg' },
{ src: 'picture2.jpg' },
{ src: 'picture4.jpg' }

Resume SharePoint Services Web Application and returns code 1387 error


Hello everyone! Newbie here. I would like to ask how to start the SharePoint Services Web Application on (WSS3.0,internal database, stanalone users) without getting error 1387 ?

I would love to provide more information regarding this issue but what I got is error 1387 displayed in the browser.

I look forward to seeing you guys feedback from your expertise angle.



How to Find out Windows service application path from Code ?

Dear frnds, Could you please help me to find out the path of  windows serivce exe ( application path ) from code?   Regards. Sajid P K  

code to run visual basic application in between desktop icon and wallpaper

Plex can anyone of you tell me the visual basic net code to make the application run between desktop icon and background wallpaper . it mean if that application is running in background the icon in the desktop should be selectable...  pleax send you code to me ....    

Can't get dataclasses1datacontext to generate code behind in .net 4.0 and vwd 2010 express


I am using a web application project in visual web developer express 2010 on Windows 7 x64 targeting .net 4.0.  I've linq to sql quite a bit with visual studio 2008 and it worked with no issues.  I added a dbml file to the root of my web site and dragged over my data model.  When I run my project, I get the following error:

Type 'DataClasses1DataContext' is not defined.  The line of code it is having a problem on is 

 Dim db As DataClasses1DataContext = New DataClasses1DataContext()

However, intellisense is recognizing dataclasses1datacontext as a valid class.  If I view the code on the dbml file, it has essentially an empty class definition.  It appears it didn't actually generate any code relating to my data model.  I tried adding system.data.linq, etc to my web.config file but it didn't make a difference.  I always get the error above.  Again, I'm using a web application project which appears to function a little differnetly than a web site project. 

Any ideas why I can't get this basic functionality that was working in 2008 to work in 2010?

Where can i place this line of code so that its accessible thruout my entire web application?


Currently im capturing the users name during certain functions, so at the moment, i have the line below within each event that i need that information. Instead of having that line everywhere, cant iplace that line in a class or something so that i can just access it by "usn" string usn = User.Identity.Name.ToString();

Release mode application throws Break instruction exception - code 80000003 when running in WinDbg


Here is the initial output of my program after running it from WinDbg:

CommandLine: "C:\Documents and Settings\Administrator\My Documents\Work\QMI_Test_Tool\QMI_UT_Source\Release\QMI Validation Tool.exe"
Symbol search path is: SRV*c:\symbols*http://msdl.microsoft.com/download/symbols
Executable search path is: 
ModLoad: 00400000 0048f000  QMI Validation Tool.exe
ModLoad: 7c900000 7c9b2000  ntdll.dll
ModLoad: 79000000 7904a000  C:\WINDOWS\system32\mscoree.dll
ModLoad: 7c800000 7c8f6000  C:\WINDOWS\system32\KERNEL32.dll
ModLoad: 77dd0000 77e6b000  C:\WINDOWS\system32\advapi32.dll
ModLoad: 77e70000 77f03000  C:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77fe0000 77ff1000  C:\WINDOWS\system32\Secur32.dll
ModLoad: 7c420000 7c4a7000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\MSVCP80.dll
ModLoad: 78130000 781cb000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\MSVCR80.dll
ModLoad: 77c10000 77c68000  C:\WINDOWS\system32\msvcrt.dll
ModLoad: 7c9c0000 7d1d7000  C:\WINDOWS\system32\SHELL32.dll
ModLoad: 77f10000 77f59000  C:\WINDOWS\system32\GDI32.dll
ModLoad: 7e410000 7e4a1000  C:\WINDOWS\system32\USER32.dll
ModLoad: 77f60000 77fd6000  C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 7c4c0000 7c53d000  C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\m

MVC application won't start: code -2147023895


I started trying to refactor my code, and made some changes to the repositories of my application. The solution still builds successfully, but when I try to run it in debug mode, the app hangs for a time, then shuts down without starting completely. The error message I get is:

The program '[3256] WebDev.WebServer40.EXE: Managed (v4.0.30319)' has exited with code -2147023895 (0x800703e9).

Since I'm not getting an exception, and Googling the error didn't yield any useful results, I'm stuck at the moment. The exit code looks somewhat like the min value for an integer, but that doesn't really mean anything to me in this context.

How to do code profiling for SharePoint application ?

How to do code profiling using clr profiler for SharePoint application in moss 2007 to identify memory consuming methods? Please help its very urgent...

cannot launch Visio 2010 application from Sharepoint 2010 featureactivated code

Dear members ! Require Your Assistance whith following issue :
I am developing Sharepoint feature which should launch Visio 2010 application.
Sharepoint is 2010 , OS is Windows 2008 R2

this line of code
app = new Application(); raise error
{"Retrieving the COM class factory for component with CLSID {00021A20-0000-0000-C000-000000000046} failed due to the following error: 80070005."}
So it is security problem . I was trying add rights for this COM object to Sharepoint account NetworkService (this recipe is providing by lot of forums), to  Users , Authenticate users even for Everyone
using dcomconfig.exe utility but without Success.
Right now I temporary change user account control settings in control panel so everything is ok but it is not a solution

Thks for you help


generate a unique code


Hiii Friends,

I have to generate a unique customer code like this-

'cbd'+first letter of customer name+incrementer


cbd is hard coded means reamain fixed in each customer code

first letter of cust_name is like Bell Companies- B


incrementer must be four digit number like 0001,0002,0888 etc.

Here incrementer should start with 0001 for each customer means

for EX-

BELL COMPANIES - CBDB0001 then it should increment for customers having name started with B

TEL POWERS- CBDT0001 then it should increment for customers having name started with T

hopefully all of u understand what i mean

plz rep asap

any help will be greatly appreciated

thanx and regards 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend