在窗口中更改任何属性时添加一个(*). [英] Adding a (*) when any of the property is changed in a window.

查看:51
本文介绍了在窗口中更改任何属性时添加一个(*).的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WPF中实现followinf功能.我的窗口中有许多下拉菜单,文本框,复选框,单选按钮,每个控件都与viewmodel中的对应属性绑定在一起,并且我也有一些属性可以启用或禁用某些具有某些特定条件的控件.

现在,当任何属性从其先前状态更改时,我想在窗口名称中添加一个(*).

谢谢您的回答.

谢谢
Arijit

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

推荐答案

您需要向所有控件添加一些附加事件处理程序,这些处理程序可以更改状态并更新一些脏"标志,这些标志指示控件的状态为熄灭与数据模型同步.使此标志的更新成为另一个事件,处理此事件,并在标志变为真时向您显示星号.

您需要处理的控件事件取决于控件.例如,组合框需要处理事件SelectionChangedTextBoxRichTextBox-事件TextChanged,依此类推.

在实现它时,请不要忘记可以将多个处理程序添加到任何事件实例的调用列表中(使用运算符"+ =").因此,以编程方式添加这些事件;这样,您可以将此机制与常规"均匀处理隔离开来.

看起来可能像这样:

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)
              //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



—SA


这篇关于在窗口中更改任何属性时添加一个(*).的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆