<small id='Qp7Kj'></small><noframes id='Qp7Kj'>

<legend id='Qp7Kj'><style id='Qp7Kj'><dir id='Qp7Kj'><q id='Qp7Kj'></q></dir></style></legend>
    • <bdo id='Qp7Kj'></bdo><ul id='Qp7Kj'></ul>
    <tfoot id='Qp7Kj'></tfoot>
  • <i id='Qp7Kj'><tr id='Qp7Kj'><dt id='Qp7Kj'><q id='Qp7Kj'><span id='Qp7Kj'><b id='Qp7Kj'><form id='Qp7Kj'><ins id='Qp7Kj'></ins><ul id='Qp7Kj'></ul><sub id='Qp7Kj'></sub></form><legend id='Qp7Kj'></legend><bdo id='Qp7Kj'><pre id='Qp7Kj'><center id='Qp7Kj'></center></pre></bdo></b><th id='Qp7Kj'></th></span></q></dt></tr></i><div id='Qp7Kj'><tfoot id='Qp7Kj'></tfoot><dl id='Qp7Kj'><fieldset id='Qp7Kj'></fieldset></dl></div>

      1. 创建一个事件来观察变量的变化

        时间:2023-09-15
        <tfoot id='TNIOe'></tfoot>
          <tbody id='TNIOe'></tbody>

          <i id='TNIOe'><tr id='TNIOe'><dt id='TNIOe'><q id='TNIOe'><span id='TNIOe'><b id='TNIOe'><form id='TNIOe'><ins id='TNIOe'></ins><ul id='TNIOe'></ul><sub id='TNIOe'></sub></form><legend id='TNIOe'></legend><bdo id='TNIOe'><pre id='TNIOe'><center id='TNIOe'></center></pre></bdo></b><th id='TNIOe'></th></span></q></dt></tr></i><div id='TNIOe'><tfoot id='TNIOe'></tfoot><dl id='TNIOe'><fieldset id='TNIOe'></fieldset></dl></div>

            1. <legend id='TNIOe'><style id='TNIOe'><dir id='TNIOe'><q id='TNIOe'></q></dir></style></legend>
              • <small id='TNIOe'></small><noframes id='TNIOe'>

                  <bdo id='TNIOe'></bdo><ul id='TNIOe'></ul>

                  本文介绍了创建一个事件来观察变量的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有:

                  public Boolean booleanValue;
                  
                  public bool someMethod(string value)
                  {
                     // Do some work in here.
                     return booleanValue = true;
                  }
                  

                  如何创建一个在 booleanValue 更改时触发的事件处理程序?有可能吗?

                  How can I create an event handler that fires up when the booleanValue has changed? Is it possible?

                  推荐答案

                  通常避免使用公共字段.尽量将它们保密.然后,您可以使用包装器属性触发您的事件.看例子:

                  Avoid using public fields as a rule in general. Try to keep them private as much as you can. Then, you can use a wrapper property firing your event. See the example:

                  class Foo
                  {
                      Boolean _booleanValue;
                  
                      public bool BooleanValue
                      {
                          get { return _booleanValue; }
                          set
                          {
                              _booleanValue = value;
                              if (ValueChanged != null) ValueChanged(value);
                          }
                      }
                  
                      public event ValueChangedEventHandler ValueChanged;
                  }
                  
                  delegate void ValueChangedEventHandler(bool value);
                  

                  这是一种简单的原生"方式来满足您的需求.还有其他方法,甚至由 .NET Framework 提供,但上述方法只是一个示例.

                  That is one simple, "native" way to achieve what you need. There are other ways, even offered by the .NET Framework, but the above approach is just an example.

                  这篇关于创建一个事件来观察变量的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 WPF FrameworkElement 上同时捕获单击和双击事件? 下一篇:如何使用委托和事件处理程序进行用户控制

                  相关文章

                • <tfoot id='THQ0i'></tfoot>

                  <small id='THQ0i'></small><noframes id='THQ0i'>

                  • <bdo id='THQ0i'></bdo><ul id='THQ0i'></ul>

                      <legend id='THQ0i'><style id='THQ0i'><dir id='THQ0i'><q id='THQ0i'></q></dir></style></legend>
                    1. <i id='THQ0i'><tr id='THQ0i'><dt id='THQ0i'><q id='THQ0i'><span id='THQ0i'><b id='THQ0i'><form id='THQ0i'><ins id='THQ0i'></ins><ul id='THQ0i'></ul><sub id='THQ0i'></sub></form><legend id='THQ0i'></legend><bdo id='THQ0i'><pre id='THQ0i'><center id='THQ0i'></center></pre></bdo></b><th id='THQ0i'></th></span></q></dt></tr></i><div id='THQ0i'><tfoot id='THQ0i'></tfoot><dl id='THQ0i'><fieldset id='THQ0i'></fieldset></dl></div>