You need to add some addition event handlers to all controls which can change the status and update some "dirty" flag which indicates the the state of controls went out of sync with the data model. Make update of this flag another event, handle this event and show you star when the flag becomes true.
The control events you need to handle depend on the control. For example, combo box needs handling the event
SelectionChanged
,
TextBox
and
RichTextBox
— the event
TextChanged
, and so on.
When you implement it, don't forget that you can add more than one handler to the invocation list of any event instance (using operator "+="). So, add those events programmatically; this way you can isolate this mechanism from "Sregular" even handling.
It can look like this:
public class MyMainWindow : Window {
public MyMainWindow() {
DirtyFlagChanged += (sender, eventArgs) => {
if (fDirtyFlag)
else
};
MyTextBox.TextChanged += (sender, eventArgs) => { DirtyFlag = true; }
MyComboBox.SelectionChanged += (sender, eventArgs) => { DirtyFlag = true; }
}
bool DirtyFlag {
get { return fDirtyFlag; }
set {
if (value == fDirtyFlag) return;
if (DirtyFlagChanged != null)
DirtyFlagChanged.Invoke(this, new System.EventArgs());
}
}
bool fDirtyFlag;
event System.EventHandler DirtyFlagChanged;
}
—SA