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 7783179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:45:48+00:00 2026-06-01T19:45:48+00:00

I am working on an interface that uses a Wcf to obtain data from

  • 0

I am working on an interface that uses a Wcf to obtain data from out database, I am having the following issue, I am using a dynamic window to display information as well as some buttons for date times, and close, etc…

However when I close the window and reopen it, it adds everything back to the form that was already there, which creates double and is causing some problems, any advice would be great, thanks in advance

Here is some code to better describe what I have….

This is the button I have on my primary form, which creates the new window

private void butMoreInf_Click(object sender, RoutedEventArgs e)
{
    winMain.DataContext = null;
    winMainContainer.DataContext = null;
    winMainContainerLeft.DataContext = null;
    winMainContainerRight.DataContext = null;
    datGrid.DataContext = null;

    //Generate the new window and panel to go within the window
    winMain.Height = 750;
    winMain.Width = 950;
    winMainContainer.Width = 1000;
    winMainContainer.HorizontalAlignment = HorizontalAlignment.Left;
    winMainContainerLeft.Width = 120;
    winMainContainerLeft.HorizontalAlignment = HorizontalAlignment.Left;
    winMainContainerRight.Width = 880;
    winMainContainerRight.HorizontalAlignment = HorizontalAlignment.Left;

    //Generate the datagrid to contain the date to be changed etc.
    datGrid.Margin = new Thickness(0, 12, 12, 12);
    datGrid.HorizontalAlignment = HorizontalAlignment.Right;

    //Generate a datepicker (start) and label
    Label labS = new Label();
    labS.Content = "Pick a start date";
    labS.Width = 100;
    labS.Margin = new Thickness(12, 1, 0, 1);
    labS.HorizontalAlignment = HorizontalAlignment.Left;

    DatePicker datPickStart = new DatePicker();
    datPickStart.Width = 100;
    datPickStart.Margin = new Thickness(12, 12, 1, 0);
    datPickStart.HorizontalAlignment = HorizontalAlignment.Left;
    datPickStart.SelectedDate = DateTime.Now.AddDays(-7);
    datStartPick = datPickStart.SelectedDate == null ? DateTime.Now : Convert.ToDateTime(datPickStart.SelectedDate);

    //Generate a datepicker (end) and label
    Label labE = new Label();
    labE.Content = "Pick an end date";
    labE.Width = 100;
    labE.Margin = new Thickness(12, 1, 0, 1);
    labE.HorizontalAlignment = HorizontalAlignment.Left;

    DatePicker datPickEnd = new DatePicker();
    datPickEnd.Width = 100;
    datPickEnd.Margin = new Thickness(12, 12, 1, 0);
    datPickEnd.HorizontalAlignment = HorizontalAlignment.Left;
    datPickEnd.SelectedDate = DateTime.Now;
    datEndPick = datPickEnd.SelectedDate == null ? DateTime.Now : Convert.ToDateTime(datPickEnd.SelectedDate);

    //Generate dropdown and label for that box
    Label labY = new Label();
    labY.Content = "";
    labY.Width = 100;
    labY.Margin = new Thickness(12, 1, 0, 1);
    labY.HorizontalAlignment = HorizontalAlignment.Left;

    ComboBox txtY = new ComboBox();
    txtY.Width = 100;
    txtY.Margin = new Thickness(12, 12, 1, 0);
    txtY.HorizontalAlignment = HorizontalAlignment.Left;
    txtY.SelectedIndex = 0;
    txtY.SelectionChanged += CLLoadErrors;

    txtY.SelectedIndex = 0;

    //Generate error list button
    Button butError = new Button();
    butError.Width = 100;
    butError.Margin = new Thickness(12, 12, 1, 0);
    butError.HorizontalAlignment = HorizontalAlignment.Left;
    butError.Content = "Get Errors";
    butError.Click += CLLoadErrors;

    //Generate clear button
    Button butClear = new Button();
    butClear.Width = 100;
    butClear.Margin = new Thickness(12, 12, 1, 0);
    butClear.HorizontalAlignment = HorizontalAlignment.Left;
    butClear.Content = "Clear Grid";
    butClear.Click += clearDataGrid;

    //Generate close button
    Button butClose = new Button();
    butClose.Width = 100;
    butClose.Margin = new Thickness(12, 12, 1, 0);
    butClose.HorizontalAlignment = HorizontalAlignment.Left;
    butClose.Content = "Close";
    butClose.Click += CLHide;

    //Add elements to the stackpanel / Also updates them before each instance
    winMainContainerLeft.UpdateLayout();

    winMainContainerLeft.Children.Add(labS);
    winMainContainerLeft.Children.Add(datPickStart);
    winMainContainerLeft.Children.Add(labE);
    winMainContainerLeft.Children.Add(datPickEnd);
    winMainContainerLeft.Children.Add(labY);
    winMainContainerLeft.Children.Add(txtY);
    winMainContainerLeft.Children.Add(butError);
    winMainContainerLeft.Children.Add(butClear);
    winMainContainerLeft.Children.Add(butClose);

    winMainContainerRight.UpdateLayout();
    winMainContainerRight.Children.Remove(datGrid);
    winMainContainerRight.Children.Add(datGrid);

    winMainContainer.UpdateLayout();
    winMainContainer.Orientation = Orientation.Horizontal;
    winMainContainer.Children.Remove(winMainContainerLeft);
    winMainContainer.Children.Add(winMainContainerLeft);
    winMainContainer.Children.Remove(winMainContainerRight);
    winMainContainer.Children.Add(winMainContainerRight);

    winMain.ResizeMode = ResizeMode.NoResize;

    //Display the new form
    winMain.UpdateLayout();
    winMain.Content = winMainContainer;
    winMain.Show();

    datGrid.MouseDoubleClick += datGridDClick;
    txtY.SelectionChanged += new SelectionChangedEventHandler(txtY_SelectionChanged);
}

Will provide more code if needed.

  • 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-01T19:45:49+00:00Added an answer on June 1, 2026 at 7:45 pm

    You are reusing the same window again and again (why?), so you need to clear out the children collections before you add new elements, otherwise every click on your button will show the window + every control you add, resulting in double/triple/… controls.

    Update: I assume you use StackPanels (from your comment / having Children enumerations). The Children enumeration is a UIElementCollection which allows to invoke the Clear method. Just call this prior to adding new controls. (on winMainContainer, winMainContainerRight and winMainContainerLeft)

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

Sidebar

Related Questions

I'm working on an application that uses Sudzc to interface with a SOAP web-service.
Newbie error? Im working on a quiz app that uses answer results from a
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of
I am working with a Web API that uses a Javascript interface to make
I'm currently working with an NSPersistentDocument subclass that uses NSOperation to import data in
I am working on a project that uses a touch-screen interface. I have a
I'm working on a site that uses this specific jQuery tab interface: http://www.queness.com/post/106/jquery-tabbed-interfacetabbed-structure-menu-tutorial I
Greetings, I've been working on a web-interface for some hardware that uses an 8-bit
I am working on an interface that requires that the user can click on
I'm working on an interface with a 3rd party app that basically needs to

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.