Wcfを使用してデータベースからデータを取得するインターフェイスに取り組んでいます。次の問題が発生しています。動的ウィンドウを使用して情報と日時のボタンを表示し、閉じるなどを行っています。
ただし、ウィンドウを閉じて再度開くと、すでに存在していたフォームにすべてが追加され、二重になり、問題が発生します。事前に感謝します。
これが私が持っているものをよりよく説明するためのいくつかのコードです...
これは、新しいウィンドウを作成するメインフォームにあるボタンです。
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);
}
必要に応じて、より多くのコードを提供します。