Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7939881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:13:52+00:00 2026-06-03T23:13:52+00:00

In my application, i am generating multiple buttons at run time and add it

  • 0

In my application, i am generating multiple buttons at run time and add it to grid as following

 for (int i = 0; i < ListOfMainCategories.Count; i++)
            {
                clsMainCategory tempCat = (clsMainCategory)ListOfMainCategories[i];
                ButtonMainMenuCat btn = CreateMainButton(tempCat.CatTitle, i);
                btn.Margin = new Thickness(0, 1, 0, 1); 
                btn.TabIndex = TabIndexNo;
                if (i == 0)
                {
                    buttonHomeMenu = btn;
                }
                btn.AddHandler(ButtonMainMenuSubSubCat.GotKeyboardFocusEvent, new RoutedEventHandler(ButtonMainMenuGotFocus), handledEventsToo: false);
                // stackTableViewMainMenu.Children.Add(btn);
                Grid.SetRow(btn, 1);
                Grid.SetColumn(btn, i + 1);
                gridHeader.Children.Add(btn);

            }

After on particular event I removed all of these buttons from Grid.

gridHeader.Children.RemoveRange(0, gridHeader.Children.Count);

Here i Think i also need to Remove or dispose or unload these button from Memory. So How can i do this task ? Please suggest

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:13:53+00:00Added an answer on June 3, 2026 at 11:13 pm

    Yuo can’t dispose of the button in the classical sense as there is nothing to dispose. You are dealing with managed code here. The memory allocation will be cleared up by the garbage collector as long as there are no references. In the code above you are keeping a reference to the button through the routed event handler so call btn.RemoveHandler before you remove it from the Grid.

    You could take a look at MSDN guidance on the WeakEvent pattern here: http://msdn.microsoft.com/en-us/library/aa970850

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's a third party application generating huge amounts of log entries on our app
I received reports that a my report generating application was not working. After my
I have a customer who's Classic ASP application is generating ASP_0147 errors. The first
From my VB application I am generating XML document based on data fetched from
Hey everyone in my web application i am generating a verification code that is
In my asp.net, C# application we are generating and downloading .xls file. But when
I have an MVC application view that is generating quite a large HTML table
i am having a application where i am generating the uibuttons dynamically want to
R is not generating in my android application package and I think it's because
I'm generating a reporting services report from an ASP.NET (MVC) based application but am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.