wpf events between two windows - c#

Can someone please illustrate for me how to set up a logic like this:
I have a WPF Control. When a button is pressed it does one of the two possible things.
A. It checks if a different WPF Window has been loaded. If it was, it triggers that window's Print method.
B. It checks if a different WPF Window has been loaded. If it was not, it instantiates that window and then triggers its Print method.
I struggle to understand the events system between two WPF Controls/Windows. It's a relatively new thing for me, so I would appreciate if someone walked me through this.
Ps. This is not a homework assignment, but rather a new hobby of mine. If its a totally noob question then just point me to a resource so I can educate myself.
Cheers!

First of all, what is the way by which you will check if new Window opened is what you need it to be ?
You might do this by comparing their Handle or their Type (public class MyWindowWithPrintMethod : Window).
There can be multiple ways of doing this.
I suggest my simple way, focusing on the WPF way, to solve your purpose in easiest way possible.
MyWindowWithPrintMethod obj_MyWindowWithPrintMethod;
private void btnNewWindow_Click(object sender, RoutedEventArgs e)
{
obj_MyWindowWithPrintMethod = new MyWindowWithPrintMethod();
obj_MyWindowWithPrintMethod.Show();
}
private void btnCheckNewWindow_Click(object sender, RoutedEventArgs e)
{
WindowInteropHelper tgtWindow = new WindowInteropHelper(obj_MyWindowWithPrintMethod);
foreach (Window w in Application.Current.Windows)
{
// Compare Handle
WindowInteropHelper wih = new WindowInteropHelper(w);
if (wih.Handle == tgtWindow.Handle)
{
((MyWindowWithPrintMethod)w).Print();
}
// Compare Type
if (w.GetType() == typeof(MyWindowWithPrintMethod))
{
((MyWindowWithPrintMethod)w).Print();
}
}
}
MyWindowWithPrintMethod.cs
public class MyWindowWithPrintMethod : Window
{
public void Print()
{
MessageBox.Show("Print invoked !");
}
}

This answer from this question about events from 2 windows may help:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Child childWindow = new Child();
childWindow.MyEvent += new EventHandler(childWindow_MyEvent);
childWindow.ShowDialog();
}
void childWindow_MyEvent(object sender, EventArgs e)
{
// handle event
MessageBox.Show("Handle");
}
}
Child window
public partial class Child : Window
{
// define event
public event EventHandler MyEvent;
protected void OnMyEvent()
{
if (this.MyEvent != null)
this.MyEvent(this, EventArgs.Empty);
}
public Child()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Child_Loaded);
}
void Child_Loaded(object sender, RoutedEventArgs e)
{
// call event
this.OnMyEvent();
}
}
The above code shows how to set up an event from one window to another. But, you might want to simply call a method in that other window instead. For example:
public void AddNewUser()
{
Window2 window = new Window2();
if (window.ShowDialog() == true)
{
// Update DataGrid
RefreshDataGrid();
}
}
If you are determined to stick with events, then you should read up on WPF routed events.

Related

How can I draw a line in my form from another class?

I have 3 classes in my program:
Arrow (it contains the logic for drawing arrow, and all required information about it, like: starting point, ending point, etc.)
Form1 (that contains the drawing area(basically panel), where this arrow will be located in the future)
UserControl, is located in Form1 (I did Form1.Controls.Add(UserControl)). It has a Form1 as a parent. In this UserControl, I have a button, when I click it, an arrow should be drawn on the Form1's drawing area.
And I'm so confused with the logic that this program should have. I tried to create Arrow class object in the UserControl.Button_Click(), and call all the Arrow's methods from there, but I can't access to Form1's controls. I also thought maybe I can create object of Arrow in the Form1. So I tried to subscribe event UserControl.Button_Click() with some Form1's delegate, but I don't know how to do it. In this case, does delegate and the method that this delegate have as a reference should be Static?
So this is how my code looks like.
(I little bit simplified and shortened my classes)
Arrow:
public class Arrow
{
public Point PointBeginning { get => pointBeginning; set => pointBeginning = value; }
public Point PointEnding { get => pointEnding; set => pointEnding = value; }
public int ArrowClickCounter { get => arrowClickCounter; set => arrowClickCounter = value; }
public void Draw(object sender, MouseEventArgs e)
{
//code for drawing
}
}
Form1:
public class Form1
{
public delegate void DrawArrowDelegate(object sender, MouseEventArgs e);
DrawArrowDelegate drawArrowDelegate = DrawArrow;
/* .. */
private void DrawArrow(object sender, MouseEventArgs e)
{
Arrow arrow = new Arrow();
arrow.PointBegining = //some point
arrow.PointEnding = //some another point
arrow.Draw(sender, e);
}
}
UserControl:
public class UserControl
{
/*...*/
private void button_MouseClick(object sender, MouseEventArgs e)
{
//And here i somehow want to call delegate. But don't know how :(
}
}
Sorry for such confused code :(
Can you please recommend me something?
Your Arrow class could potentially have a DrawMethod which takes a control
Your UserControl, should publish events
You form should listen to the UserControl Events
Your form should override OnPaint to draw the method on demand
Arrow class:
public class Arrow
{
public Point PointBeginning { get; set; }
public Point PointEnding { get; set; }
public int ArrowClickCounter { get; set; }
public void Draw()
{
//code for drawing
}
}
UserControl.cs:
public delegate void CreateArrowEventArgs(Arrow arrow);
public event CreateArrowEventArgs OnCreateArrow;
private void button1_Click(object sender, EventArgs e)
{
if(this.OnCreateArrow!=null)
{
// Create Arrow object which you will have access to in your Form
Arrow arrowToDraw = new Arrow();
// Fire The Event
this.OnCreateArrow.Invoke(arrowToDraw);
}
}
Form codebehind :
private void Form1_Load(object sender, EventArgs e)
{
// Create User Control
var UserCtrl = new UserControl1();
// Register Event
UserCtrl.OnCreateArrow += UserCtrl_OnCreateArrow;
//Add Control to Form
this.Controls.Add(UserCtrl);
}
// You get the Arrow object for use here
private void UserCtrl_OnCreateArrow(Arrow arrow)
{
arrow.Draw();
}
It sounds like you're having trouble accessing Form1's Controls, so try this:
Form1 f1 = new Form1();
foreach(Button b in f1.Controls)
{
//Your code..
}
There's also:
this.Controls
And, with calling the events of another control,
button1_Click(sender, e);
As for adding an event to the click of, say, a button,
button1.Click += button1_Click;
Those should work to access the controls.
I can provide more information if needed :)

How to update list on one window when some event trigger on another window in WPF

How to update list on one window when some event trigger on another window in WPF.
i just want to know how to listen to the event of one window from another window.
You'll have to pass the object to the new window and then create a new event handler for it on the second window.
First Window Code:
public FirstWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SecondWindow sWindow = new SecondWindow(btnFirstWindow);
sWindow.Show();
}
Second Window Code:
private Button firstWindowButton;
public SecondWindow(Button firstWindowButton)
{
this.firstWindowButton = firstWindowButton;
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
firstWindowButton.Click += firstWindowButton_Click;
}
void firstWindowButton_Click(object sender, RoutedEventArgs e)
{
lblShowUser.Content = "First window button clicked on: " + DateTime.Now.ToString();
}
I've added a list to the first window and events on the second window for you:
Here is the first windows code:
public FirstWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
String[] items = { "Item 1", "Item 2", "Item 3" };
listItems.ItemsSource = items;
SecondWindow sWindow = new SecondWindow(btnFirstWindow, listItems);
sWindow.Show();
}
Second windows code:
private Button firstWindowButton;
private ListBox firstWindowListBox;
public SecondWindow(Button firstWindowButton, ListBox firstWindowListBox)
{
this.firstWindowButton = firstWindowButton;
this.firstWindowListBox = firstWindowListBox;
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
firstWindowButton.Click += firstWindowButton_Click;
firstWindowListBox.MouseDoubleClick += firstWindowListBox_MouseDoubleClick;
}
void firstWindowListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (firstWindowListBox.SelectedItem != null)
{
lblShowUser.Content = "First window list box selected item: " + firstWindowListBox.SelectedItem.ToString();
}
}
void firstWindowButton_Click(object sender, RoutedEventArgs e)
{
lblShowUser.Content = "First window button clicked on: " + DateTime.Now.ToString();
}
What did you tried so far?
Is one window creating the other window?
Normally i would call a method of the child window.
If the child window wants to trigger the parent, it should be done with an event.
like: pseudo
public class FormParent : Form
{
public void OpenChild()
{
// create the child form
FormChild child = new FormChild();
// register the event
child.DataUpdated += Child_DataUpdated;
// ....
// parent to child (method call)
child.DoSomething();
}
public void Child_DataUpdated(object sender, EventArgs e)
{
// refresh the list.
}
}
public class FormChild : Form
{
public void DoSomething()
{
// ....
// if the list should be refreshed.
// call event from child to parent.
if(DataUpdated != null)
DataUpdated(this, EventArgs.Empty);
}
public event EventHandler DataUpdated;
}
Keep in mind, the parent knows the structure of the child. (method call)
The child, doesn't know anything about the structure of the parent (events)
This way you can reuse the child on different solutions. (not dependend on code)
This is basically same question like passing data between two windows. Sender is the window which has trigger, receiver is the one what process.
You can have coupled solution, when one of window should know about other. If you pass instance of receiver to sender, then sender will be able to call a public method of receiver. If you pass instance of sender to receiver, then receiver can subscribe to event of public control (don't do that) or special dedicated form event (just for this reason - to trigger something somewhere else).
Decoupled solution would be to have separate class (provider?), which exposes event and method to trigger that event. Receiver will subscribe to event, sender will trigger it, none of them knows about each other, none must trigger or subscribe.

How to call mainform method in another form in usercontrol C#

I am working with windowsFrom in c#. I am trying to call mainfrom method in one of the from in user control.
I have mainfrom like this
namespace Project
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public void TempCommand()
{
StartTemp();
}
}
}
I have the button click in the user control. When i click that button then it will open another form. I have the code like this in the user control.
private TempCalib _tempCalib = new TempCalib();
private void calibBtn_Click(object sender, EventArgs e)
{
_tempCalib.Show();
}
it will open another from and i have one button in that from. I need to call mainfrom method when i click "Ok" button in this from.
namespace Project
{
public partial class TempCalib : Form
{
public TempCalib()
{
InitializeComponent();
}
private void OkButton_Click(object sender, EventArgs e)
{
// I need to call the mainfrom "TempCommand" method here.
this.Hide();
}
}
}
Can anyone help me how to do this.
Thanks.
Quick answer
Just add a reference to the primary form in your secondary form:
public partial class TempCalib : Form
{
private MainForm _main
public TempCalib(MainForm main) : this()
{
_main = main;
}
/// Other stuffs
}
Then assign value when you construct your secondary form:
private TempCalib _tempCalib;
private void calibBtn_Click(object sender, EventArgs e)
{
if (_tempCalib == null)
_tempCalib = new TempCalib(this);
_tempCalib.Show();
}
If calibBtn_Click isn't inside MainForm (but it's inside a UserControl on it) then you can replace _tempCalib initialization with:
_tempCalib = new TempCalib((MainWindow)FindForm());
You'll be then able to call the primary form:
private void OkButton_Click(object sender, EventArgs e)
{
_main.TempCommand();
this.Hide();
}
Notes: this is just one option, you may create a property to hold MainForm reference (so secondary form can be reused and it'll be more designer friendly) moreover TempCalib is not an UserControl but a Form (pretty raw but for an UserControl you may just check its parent Form and cast it to proper type).
Improvements
Such kind of references are often an alert. Usually UI components shouldn't not be so coupled and a public Form's method to perform something very often is the signal that you have too much logic in your Form. How to improve this?
1. DECOUPLE CONTROLS. Well a first step may be to decouple them a little bit, just add an event in TempCalib and make MainForm its receiver:
public partial class TempCalib : Form
{
public event EventHandler SomethingMustBeDone;
private void OkButton_Click(object sender, EventArgs e)
{
OnSomethingMustBeDone(EventArgs.Empty); / TO DO
this.Hide();
}
}
Then in MainForm:
private TempCalib _tempCalib;
private void calibBtn_Click(object sender, EventArgs e)
{
if (_tempCalib == null)
{
_tempCalib = new TempCalib();
_tempCalib.SomethingMustBeDone += _tempCalib_SomethingMustBeDone;
// In _tempCalib_SomethingMustBeDone you'll invoke proper member
// and possibly hide _tempCalib (remove it from OkButton_Click)
}
_tempCalib.Show();
}
2. DECOUPLE LOGIC FROM CONTROLS. UI changes pretty often, logic not (and when it changes probably isn't in parallel with UI). This is just the first step (now TempCalib isn't aware of who will use it). Next step (to be performed when too much things happen inside your form) is to remove this kind of logic from the form itself. Little example (very raw), keep TempCalib as before (with the event) and change MainForm to be passive:
public partial class MainForm : Form
{
public event EventHandler Calibrate;
protected virtual void OnCalibrate(EventArgs e)
{
// TODO
}
}
Now let's create a class to control the flow and logic:
public class MyTaskController
{
private MainForm _main;
private TempCalib _tempCalib;
public void Start()
{
_main = new MainForm();
_main.Calibrate += OnCalibrationRequested;
_main.Show(); // Or whatever else
}
private void OnCalibrationRequested(object sender, EventArgs e)
{
if (_tempCalib == null)
{
_tempCalib = new TempCalib();
_tempCalib.SomethingMustBeDone += OnSomethingMustBeDone();
}
_tempCalib.Show();
}
private OnSomethingMustBeDone(object sender, EventArgs e)
{
// Perform the task here then hide calibration window
_tempCalib.Hide();
}
}
Yes, you'll need to write much more code but this will decouple logic (what to do as response to an action, for example) from UI itself. When program grows up this will help you to change UI as needed keeping logic unaware of that (and in one well defined place). I don't even mention that this will allow you to use different resources (people) to write logic and UI (or to reuse logic for different UI, WinForms and WPF, for example). Anyway IMO the most obvious and well repaid benefit is...readability: you'll always know where logic is and where UI management is, no search, no confusion, no mistakes.
3. DECOUPLE LOGIC FROM IMPLEMENTATION. Again you have more steps to perform (when needed). Your controller is still aware of concrete types (MainForm and TempCalib). In case you need to select a different form at run-time (for example to have a complex interface and a simplified one or to use dependency injection) then you have to decouple controller using interfaces. Just an example:
public interface IUiWindow
{
void Show();
void Hide();
}
public interface IMainWindow : IUiWindow
{
event EventHandler Calibrate;
}
public interface ICalibrationWindow : IUiWindow
{
event EventHandler SomethingMustBeDone;
}
You could use a custom event that is declared in your UserControl. Then your form needs to handle this event and call the method you want to call. If you let the UserControl access your form, you are hard-linking both with each other which decreases reusability of your UserControl.
For example, in TempCalib:
public delegate void OkClickedHandler(object sender, EventArgs e);
public event OkClickedHandler OkClicked;
private void OkButton_Click(object sender, EventArgs e)
{
// Make sure someone is listening to event
if (OkClicked == null) return;
OkClicked(sender, e);
this.Hide();
}
in your mainform:
private void Mainform_Load(object sender, EventArgs e)
{
_tempCalib.OkClicked += CalibOkClicked;
}
private void CalibOkClicked(Object sender, EventArgs e)
{
StartTemp();
}
You create an event in your usercontrol and subscribe to this in the mainform.
That is the usual way.
Form1 Code:
UserControl1 myusercontrol = new UserControl1();
public void TabClose(Object sender,EventArgs e)
{
int i = 0;
i = tabControl1.SelectedIndex;
tabControl1.TabPages.RemoveAt(i);
}
private void Form1_Load(object sender, EventArgs e)
{
myusercontrol.Dock = DockStyle.Fill;
TabPage myTabPage = new TabPage();
myTabPage.Text = "Student";
myTabPage.Controls.Add(myusercontrol);
tabControl1.TabPages.Add(myTabPage);
myusercontrol.OkClick += TabClose;
}
UserControl1 Code:
public delegate void OkClickedHandler(Object sender, EventArgs e);
public partial class UserControl1 : UserControl
{
public event OkClickedHandler OkClick;
public UserControl1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
if (OkClick == null) return;
OkClick(sender, e);
}
}
Try this:
From user control try this:
MainForm form = this.TopLevelControl as MainForm;
form.TempCommand();

Accessing a Parent form button from a Child form button

I have a program that has a parent form which then creates a child form. Upon clicking the updateButton within the child form, I want the searchButton within the parent form to fire.
However I get an error for protection reasons. I have tried setting everything Public just to see, still wont work for me.
Error 1 'SalesSystem.SystemForm.searchButton' is inaccessible due to
its protection level SalesSystem\UpdateForm.cs 111 20 SalesSystem
This is what I have so far.
Parent Code
namespace SalesSystem
{
public partial class SystemForm : Form
{
public SystemForm()
{
InitializeComponent();
}
protected void searchButton_Click(object sender, EventArgs e)
{
//search code
}
private void updateButton_Click(object sender, EventArgs e)
{
try
{
UpdateForm upForm = new UpdateForm(resultBox.SelectedItems[0].Text, dbdirec, dbfname);
upForm.ShowDialog(this);
}
catch (Exception)
{
//
}
}
}
Child Code
namespace SalesSystem
{
public partial class UpdateForm : Form
{
public UpdateForm(string selectedPerson, string dbdirec, string dbfname)
{
InitializeComponent();
}
private void updateButton_Click(object sender, EventArgs e)
{
//do stuff
SystemForm parent = (SystemForm)this.Owner;
parent.searchButton.PerformClick();
this.Close();
}
}
}
Your searchButton button control is set to private by default in WinForm. You've said you set everything to public but I assume you mean you've set everything in the code you've posted to public. There are a few ways to fix this. The direct fix would be to simply go to Visual Studio designer, select the button, and set its Modifier property to internal or public.
However, it seems you're closing your form straight after so I'd just have my parent form subscribe to the FormClosing event of the form.
UpdateForm upForm = new UpdateForm(resultBox.SelectedItems[0].Text, dbdirec, dbfname);
upForm.FormClosing += (s, o) =>
{
//your code for what the parent class should do
};
upForm.ShowDialog(this);
If you're not closing the form then you can create your own event handler that your parent form subscribes to.
You have 2 options:
create a public void search() method in your parent form. Then, instead of accessing the the button on the parent form and invoking its click event, you run the search code directly. The new method is not tied to a GUI element and accessing it from a different form is no problem.
The better solution is to create a delegate. A delegate is an execution target that will be assigned at run time. The parent form still has a public void search() method. And when it creates the child form, it will pass the name of that function as parameter. The child form has no knowledge about the parent form (as opposed to the first option where the child MUST know that there is a method called search()). When it is time to inform whoever created the child form, the delegate is called. This is a small example:
public partial class SystemForm : Form
{
public delegate void dSearch();
public SystemForm()
{
InitializeComponent();
}
protected void searchButton_Click(object sender, EventArgs e)
{
search();
}
private void search()
{
//search code
}
private void updateButton_Click(object sender, EventArgs e)
{
try
{
UpdateForm upForm = new UpdateForm(resultBox.SelectedItems[0].Text, dbdirec, dbfname, search);
upForm.ShowDialog(this);
}
catch (Exception)
{
//
}
}
}
And the child form:
public partial class UpdateForm : Form
{
private SystemForm.dSearch _target;
public UpdateForm(string selectedPerson, string dbdirec, string dbfname, SystemForm.dSearch target)
{
_target = target;
InitializeComponent();
}
private void updateButton_Click(object sender, EventArgs e)
{
//do stuff
_target();
this.Close();
}
}
You should use the "Model View Controller" or "Model View Presenter" pattern to approach this kind of thing.
Each form should only be concerned with displaying its contents to the user. When it comes to responding to UI events such as button clicks, each form (i.e. each "View") should simply raise an event which informs the controller/presenter that something has happened.
The controller/presenter should then respond appropriately. Then the logic that wires together different forms (such as the parent and child forms in your example) is encapsulated in the Controller class. Such logic does not really belong in either of the forms.
I wrote an example that demonstrates a simple design to do this sort of thing in another answer some time ago. Rather than copy/paste it all here, I'll just give you a link to it:
How to make Form1 label.text change when checkbox on form2 is checked?
You'll have to scroll down to see my answer. It's broadly similar to what you're doing; hopefully it will make sense to you! Follow the instructions to make a test application and run it to see what happens.
I'm tired and might be missing something but that is correct behaviour.
Your child form does not directly inherit from your parent form.
Your parent form has a protected level, so only it and classes that extend it can access the method.
2 solutions:
Change your child form to:
public partial class UpdateForm : SystemForm
Change method to public
public void searchButton_Click(object sender, EventArgs e)
You could expose a Search Event from your UpdateForm and subscribe to this event in the SystemForm
namespace SalesSystem
{
public partial class SystemForm : Form
{
public SystemForm()
{
InitializeComponent();
}
protected void searchButton_Click(object sender, EventArgs e)
{
//search code
}
private void updateButton_Click(object sender, EventArgs e)
{
try
{
UpdateForm upForm = new UpdateForm(resultBox.SelectedItems[0].Text, dbdirec, dbfname);
upForm.OnSearch += Search;
upForm.ShowDialog(this);
}
catch (Exception)
{
//
}
}
private void Search(string searchParameter)
{
....
}
}
namespace SalesSystem
{
public delegate void SearchEventHandler(string searchParameter);
public partial class UpdateForm : Form
{
public event SearchEventHandler OnSearch;
public UpdateForm(string selectedPerson, string dbdirec, string dbfname)
{
InitializeComponent();
}
private void updateButton_Click(object sender, EventArgs e)
{
//do stuff
OnSearch("SearchThis");
this.Close();
}
}
}

How to detect that a Window has used up its "ShowDialog" call

In WPF you get to call ShowDialog on a window exactly once. After that it is done for.
Seems kind of lame to me, but those are the rules. If you call ShowDialog again you get this exception:
Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed
What I want to know is: How can I take a Window (or UserControl really) and check to see if it has had ShowDialog called (so I know to new up a different one before calling ShowDialog again).
Something like this:
public void ShowListOfClients()
{
// | This is the method I want to write
// V
RefreshViewIfNeeded(_myWindowOrUserControlThatShowsAList);
FillWindowWithBusinessData(_myWindowOrUserControlThatShowsAList);
_myWindowOrUserControlThatShowsAList.ShowDialog();
}
NOTE: Clearly in the above example it would be easier to just create a new WindowOrUserControlThatShowsAList every time I enter the method. But please consider the question more that the dumbed down example.
This isn't exclusive to ShowDialog(), Show() does it too. And no, there is no IsDisposed property to check. IsLoaded is only half a solution, it will be false for the 1st invocation as well.
First approach is to just make a dialog that can be re-shown:
public bool CloseAllowed { get; set; }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
if (!CloseAllowed) {
this.Visibility = System.Windows.Visibility.Hidden;
e.Cancel = true;
}
}
The next one is to explicitly keep track of the health of the object reference:
private Window1 win = new Window1(); // say
private void button1_Click(object sender, RoutedEventArgs e) {
if (win == null) {
win = new Window1();
win.Closing += delegate { win = null; };
}
win.ShowDialog();
}
Well the dirty way to do it would be to catch the exception.
The clean way to do it would be to show a window with ShowDialog, and destroy (lose reference to, etc) the window when the function returns. The view should not be tightly coupled with the models (you are using MVVM right?) so creating new visual objects for each client view should not be an issue.
Easy way to deal with this problem without messing up with the Closing event :
public partial class MainWindow
{
private SomeCustomWindow _someCustomWindow;
public MainWindow()
{
InitializeComponent();
}
private void OnOpenCustomWindowButtonClick(object sender, RoutedEventArgs e)
{
if (_someCustomWindow != null)
_someCustomWindow.Close();
_someCustomWindow = new SomeCustomWindow();
_someCustomWindow.ShowDialog();
}
private void OnWindowClosing(object sender, CancelEventArgs e)
{
if (_someCustomWindow!= null)
_someCustomWindow.Close();
}
}

Categories

Resources