Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to implement the followinf funtionality in WPF.I have a numbers of dropdown, text box, checkbox, radiobutton in my window and every control is binded with the corrosponding property in the viewmodel and I have also some property to enable or disable some of the controls with some specific condition.

Now I want to add a (*) in the window name when any of the property is changed form it's previous state.

Thanks for your ans.

Thanking you,
Arijit
Posted

1 solution

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:

C#
public class MyMainWindow : Window {

    public MyMainWindow() {
        //... 
        DirtyFlagChanged += (sender, eventArgs) => {
           if (fDirtyFlag)
              //show star
           else
              //clear star
        };
        MyTextBox.TextChanged += (sender, eventArgs) => { DirtyFlag = true; } //will trigger star, but only on first change
        MyComboBox.SelectionChanged += (sender, eventArgs) => { DirtyFlag = true; } 
        // and so on, for all controls which can change the data layer
  } //MyMainWindow (constructor)
    
    bool DirtyFlag {
        get { return fDirtyFlag; }
        set {
            if (value == fDirtyFlag) return;
            if (DirtyFlagChanged != null)
               DirtyFlagChanged.Invoke(this, new System.EventArgs()); 
        } //set DirtyFlag
    } //DirtyFlag

    bool fDirtyFlag;

    event System.EventHandler DirtyFlagChanged;

} //class MyMainWindow


—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900