{"id":266877,"date":"2015-10-27T13:11:03","date_gmt":"2015-10-27T10:11:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=266877"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=266877","title":{"rendered":"\u041f\u0438\u043b\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 Binder\u2026"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ee5\/1cf\/699\/ee51cf699908343bc6fd59a83bad84c1.png\" alt=\"image\"\/><\/p>\n<p>  \u0414\u0435\u043b\u043e \u0431\u044b\u043b\u043e \u0442\u0430\u043a\u2026 \u043c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u043e\u0434\u043d\u043e\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0431\u0438\u043d\u0434\u0435\u0440. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0430 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443, \u0430 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u042f \u0432 \u043a\u043e\u0434\u0435 \u0441\u0442\u043e \u0442\u044b\u0449 \u0440\u0430\u0437 \u043c\u0435\u043d\u044f\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u2014 \u0438 \u043d\u0435 \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431 \u0433\u043e\u043b\u043e\u0432\u0430 \u0431\u043e\u043b\u0435\u043b\u0430 \u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u0442\u0430\u043c textbox&#8217;\u0430\u0445. \u0425\u043e\u0447\u0443, \u0447\u0442\u043e\u0431 \u043e\u043d\u0438 \u0441\u0430\u043c\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0438\u0441\u044c\u2026<\/p>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0443 \u0431\u0443\u0440\u0436\u0443\u0435\u0432 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0431\u0438\u043d\u0434\u0435\u0440, \u043e\u0447\u0435\u043d\u044c \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u043a\u0440\u0443\u0442\u043e\u0439. \u041d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u043a\u0440\u0443\u0442\u043e\u0439, \u0447\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0431\u0435\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u0422\u043e\u0447\u043d\u0435\u0435, \u0435\u0435 \u0447\u0435\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u2014 \u0438 \u0432\u0435\u0437\u0434\u0435 \u043d\u0435\u0432\u043d\u044f\u0442\u043d\u043e, \u043d\u0435\u0447\u0435\u0442\u043a\u043e. \u041a\u043e\u0440\u043e\u0447\u0435, \u043f\u043b\u044e\u043d\u0443\u043b \u044f \u043d\u0430 \u0431\u0443\u0440\u0436\u0443\u0439\u0441\u043a\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0438 \u0440\u0435\u0448\u0438\u043b \u0412\u041e\u0422 \u042d\u0422\u0418\u041c\u0418 \u0420\u0423\u041a\u0410\u041c\u0418 \u0437\u0430\u043f\u0438\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0431\u0438\u043d\u0434\u0435\u0440\u2026 \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c \u2014 \u043d\u0430\u0432\u0435\u0440\u043d\u043e, \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0421#-\u043a\u0440\u0443\u0433\u043e\u0437\u043e\u0440\u0430.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<p>  <b>\u0417\u0430\u0434\u0430\u0447\u0430:<\/b> \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u044f\u043a\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u043a\u0441\u044b) \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0441\u044f \u0438 \u0441\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b (\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438). <\/p>\n<p>  \u041a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u0432\u0435 \u0432\u0435\u0449\u0438: namespace System.Reflection \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 set-\u0430\u043a\u0441\u0435\u0441\u0441\u043e\u0440\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430. \u0427\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 \u00abPropertyChanged\u00bb. \u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432 \u043a\u043e\u0434\u0435:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043b\u0430\u0441\u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">string _Property;         public string Property         {             get { return this._Property; }             set             {                 this._Property = value;                 if (this.PropertyIsChanged != null) { this.PropertyIsChanged.Invoke(); }             }         }  public event Action PropertyIsChanged; <\/code><\/pre>\n<\/p><\/div>\n<\/div>\n<p>  \u041f\u0440\u043e\u0448\u0443 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0432\u0435 \u0432\u0435\u0449\u0438: <\/p>\n<p>  1) if (this.PropertyIsChanged != null) { this.PropertyIsChanged.Invoke(); \u2014 \u044d\u0442\u043e \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0440\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 nullReference-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. <\/p>\n<p>  2) public event Action PropertyIsChanged; \u2014 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u0430\u043a \u0438 \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u043e, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043e \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c public, <u>\u0438 \u0432 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0443 \u043f\u043e\u043b\u043e\u0436\u0435\u043d \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442 Action, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 void \u0438 \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432<\/u>. \u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0434\u0435\u043b\u0435\u0433\u0430\u0442, \u0430 \u043d\u0435 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0440\u0443\u0433\u043e\u0439? \u0414\u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u043a \u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u043d\u0430\u0448 \u0431\u0438\u043d\u0434\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442 \u0441\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0438 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0434\u0435\u043b\u043e: \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 (\u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0440\u0430\u0431\u043e\u0442\u044b set-\u0430\u043a\u0441\u0435\u0441\u0441\u043e\u0440\u0430 \u043e\u043d\u043e \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u0438\u043b\u043e\u0441\u044c, \u0442\u0430\u043c \u0436\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b event \u2014 \u0435\u0441\u043b\u0438 \u0443 \u043d\u0435\u0433\u043e \u0431\u044b\u043b \u0445\u043e\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e) \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 .Text) \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0430. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0431\u0438\u043d\u0434\u043e\u0432\u0441\u043a\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 void \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>  \u0412\u0441\u0435, \u043e\u0431\u044a\u0435\u043a\u0442-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0433\u043e\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c \u043a\u043e\u0434 \u0431\u0438\u043d\u0434\u0435\u0440\u0430. <\/p>\n<p>  \u0417\u043d\u0430\u0447\u0438\u0442, \u0443 \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0431\u0438\u043d\u0434\u0435\u0440\u0430 \u0432\u0441\u0435\u0433\u043e \u0447\u0435\u0442\u044b\u0440\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043b\u044f:   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043e\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Binder<\/b><\/p>\n<div class=\"spoiler_text\">\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">Control _targetControl;         \/\/\/ &lt;summary&gt;         \/\/\/ Get; set-once.         \/\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Control (\u0446\u0435\u043b\u044c), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443.         \/\/\/ &lt;\/summary&gt;         public Control TargetControl         {             get { return this._targetControl; }             set              {                 if (this._targetControl != null) { \/* do nothing *\/ }                 else { this._targetControl = value; }             }         }          string _targetControlProperty;         \/\/\/ &lt;summary&gt;         \/\/\/ Get; set-once.         \/\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 Control'a,         \/\/\/ \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043e \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0443-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443.         \/\/\/ &lt;\/summary&gt;         public string TargetControlProperty         {             get { return this._targetControlProperty; }             set              {                 if (this._targetControlProperty != null) { \/* do nothing *\/ }                 else { this._targetControlProperty = value; }              }         } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">\/\/\/ &lt;summary&gt;         \/\/\/ \u041e\u0431\u044a\u0435\u043a\u0442, \u043a \u043f\u043e\u043b\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d Control.         \/\/\/ &lt;\/summary&gt;         object _dataSourceObject;          \/\/\/ &lt;summary&gt;         \/\/\/ Get; set-once.         \/\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a,         \/\/\/ \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d Control.         \/\/\/ &lt;\/summary&gt;         public Object DataSourceObject         {             get { return this._dataSourceObject; }             set             {                 if (this._dataSourceObject != null) { \/* do nothing *\/ }                 else { this._dataSourceObject = value; }             }         }          string _dataSourceObjectProperty;         \/\/\/ &lt;summary&gt;         \/\/\/ Get; set-once.         \/\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0448\u0430\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430,          \/\/\/ \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d Control(\u0446\u0435\u043b\u044c).         \/\/\/ &lt;\/summary&gt;         public string DataSourceObjectProperty         {             get { return this._dataSourceObjectProperty; }             set              {                 if (this._dataSourceObjectProperty != null) { \/* do nothing *\/ }                 else { this._dataSourceObjectProperty = value; }             }         } <\/code><\/pre>\n<p>  <\/div>\n<\/div><\/div>\n<\/div>\n<p>  \u0418\u0434\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0438\u043d\u0434\u0435\u0440\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public SimpleBinder(             Control targetControl,             string targetControlProperty,             object dataSourceObject,             string dataSourceProperty,             string dataSourcePropertyChanged = &quot;&quot;)         {             \/\/ safety checks             CheckIfPropertyExists(targetControl, targetControlProperty);             CheckIfPropertyExists(dataSourceObject, dataSourceProperty);             \/\/ end safety              this._targetControl = targetControl;             this._targetControlProperty = targetControlProperty;              this._dataSourceObject = dataSourceObject;             this._dataSourceObjectProperty = dataSourceProperty;              if (dataSourcePropertyChanged == String.Empty) { this.Binding(); }             else              {                 CheckIfEventExists(dataSourceObject, dataSourcePropertyChanged);                 this.Binding(dataSourcePropertyChanged, null);              }         } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0447\u0435\u0442\u044b\u0440\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044f\u043c \u043a\u043b\u0430\u0441\u0441\u0430) \u0438 \u043e\u0434\u0438\u043d \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439. \u0421\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u044d\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 public-\u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c. \u042f \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b \u0432\u044b\u0448\u0435. \u041f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c \u0435\u0449\u0435 \u0440\u0430\u0437, \u043b\u044e\u0431\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0430, \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0443 \u0441\u0435\u0431\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u2026 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u0438\u043d\u0434\u0435\u0440\u0430. <\/p>\n<p>  \u0410 \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439, \u0442\u043e \u043d\u0443\u0436\u0435\u043d \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430::  <\/p>\n<pre><code class=\"cs\">if (dataSourcePropertyChanged == String.Empty) { this.Binding(); }             else              {                 CheckIfEventExists(dataSourceObject, dataSourcePropertyChanged);                 this.Binding(dataSourcePropertyChanged, null);              } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. \u0422\u043e\u0433\u0434\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 .Binding() \u0431\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.   <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">this.Binding()<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void Binding()         {             this.Binding_SetValueToControl(this._targetControlProperty, this.DataSourceObjectProperty);         }  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043a\u043e\u0434\u0430, .Binding() \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 private-\u043c\u0435\u0442\u043e\u0434 .Binding_SetValueToControl()\u2026 \u0432\u043e\u0442 \u043e\u043d:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">.Binding_SetValueToControl()<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void Binding_SetValueToControl(             string targetControlProperty,             string dataSourceProperty)         {             this.TargetControl.GetType()                 .GetProperty(targetControlProperty) \/\/ \u0421\u0422\u0420\u041e\u041a\u0410 \u0421 \u041d\u0410\u0417\u0412\u0410\u041d\u0418\u0415\u041c \u0421\u0412\u041e\u0419\u0421\u0422\u0412\u0410                 .SetValue(this.TargetControl,                           this.DataSourceObject.GetType()                           .GetProperty(dataSourceProperty) \/\/ \u0421\u0422\u0420\u041e\u041a\u0410 \u0421 \u041d\u0410\u0417\u0412\u0410\u041d\u0418\u0415\u041c \u0421\u0412\u041e\u0419\u0421\u0422\u0412\u0410                           .GetValue(this.DataSourceObject)                           );         } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412\u043e\u0442 \u0442\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0435 \u0441\u0430\u043c\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438. \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 .GetProperty() \u0438 \u0434\u0440\u0443\u0433\u0438\u0445, \u043d\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0442\u0443\u0442 \u0432\u0441\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u044f\u0441\u043d\u043e. \u041c\u0435\u043b\u044c\u043a\u043e\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0430 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u2014 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c System.Reflection. <\/p>\n<p>  \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u0430 \u043a\u0430\u043a \u0436\u0435 \u043d\u0430\u0448 \u0431\u0438\u043d\u0434\u0435\u0440 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435?  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">private void Binding_DataSourcePropertyChangedEvent(             string dataSourcePropertyChanged,             Delegate propertyChangedEventHandler = null             )         {             if (propertyChangedEventHandler != null)             {                 this.DataSourceObject.GetType()                     .GetEvent(dataSourcePropertyChanged)                     .AddEventHandler(this.DataSourceObject, propertyChangedEventHandler);             }             else             {                 SimpleBinder RefToThis = this;                 this.DataSourceObject.GetType()                     .GetEvent(dataSourcePropertyChanged)                     .AddEventHandler(this.DataSourceObject,                                      new Action(                                          () =&gt;                                          { RefToThis.UpdateControl(RefToThis.GetDataSourcePropertyValue()); }                                          ));             }         }  <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u0435 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438, .AddEventHandler() \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0431\u0438\u043d\u0434\u043e\u0432\u0441\u043a\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043a \u0442\u043e\u043c\u0443 public-\u0441\u043e\u0431\u044b\u0442\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 (\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u043e\u0441\u044c \u0432 \u0435\u0433\u043e set-\u0430\u043a\u0441\u0435\u0441\u0441\u043e\u0440\u0435!). \u0417\u0434\u0435\u0441\u044c: 1) \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0434\u0435\u043b\u0435\u0433\u0430\u0442 \u0442\u0438\u043f\u0430 Action \u0438 2) \u0435\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434, \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f (\u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438 \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u2014 \u043d\u0435 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435). \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0432\u0441\u0435.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a \u044d\u0442\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f:  <\/p>\n<pre><code class=\"cs\"> SourceObj = new SomeClass(&quot;Text?&quot;); \/\/ \u043e\u0431\u044a\u0435\u043a\u0442-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a. &quot;Text?&quot; - \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e.              SimpleBinder txtBoxBinder = new SimpleBinder(this.label1, &quot;Text&quot;, \/\/ Control \u0438 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b                                              SourceObj, &quot;Property&quot;, \/\/ \u041e\u0431\u044a\u0435\u043a\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e                                              &quot;PropertyIsChanged&quot;); \/\/ \u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.   <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0435.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/269627\/\"> http:\/\/habrahabr.ru\/post\/269627\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ee5\/1cf\/699\/ee51cf699908343bc6fd59a83bad84c1.png\" alt=\"image\"\/><\/p>\n<p>  \u0414\u0435\u043b\u043e \u0431\u044b\u043b\u043e \u0442\u0430\u043a\u2026 \u043c\u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u043e\u0434\u043d\u043e\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0431\u0438\u043d\u0434\u0435\u0440. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043e\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0430 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443, \u0430 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u042f \u0432 \u043a\u043e\u0434\u0435 \u0441\u0442\u043e \u0442\u044b\u0449 \u0440\u0430\u0437 \u043c\u0435\u043d\u044f\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u2014 \u0438 \u043d\u0435 \u0445\u043e\u0447\u0443, \u0447\u0442\u043e\u0431 \u0433\u043e\u043b\u043e\u0432\u0430 \u0431\u043e\u043b\u0435\u043b\u0430 \u043e \u0432\u0441\u044f\u043a\u0438\u0445 \u0442\u0430\u043c textbox&#8217;\u0430\u0445. \u0425\u043e\u0447\u0443, \u0447\u0442\u043e\u0431 \u043e\u043d\u0438 \u0441\u0430\u043c\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0438\u0441\u044c\u2026<\/p>\n<p>  \u0412\u043e\u043e\u0431\u0449\u0435-\u0442\u043e, \u0443 \u0431\u0443\u0440\u0436\u0443\u0435\u0432 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0431\u0438\u043d\u0434\u0435\u0440, \u043e\u0447\u0435\u043d\u044c \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u043a\u0440\u0443\u0442\u043e\u0439. \u041d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u043a\u0440\u0443\u0442\u043e\u0439, \u0447\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0431\u0435\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u0422\u043e\u0447\u043d\u0435\u0435, \u0435\u0435 \u0447\u0435\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u2014 \u0438 \u0432\u0435\u0437\u0434\u0435 \u043d\u0435\u0432\u043d\u044f\u0442\u043d\u043e, \u043d\u0435\u0447\u0435\u0442\u043a\u043e. \u041a\u043e\u0440\u043e\u0447\u0435, \u043f\u043b\u044e\u043d\u0443\u043b \u044f \u043d\u0430 \u0431\u0443\u0440\u0436\u0443\u0439\u0441\u043a\u0438\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0438 \u0440\u0435\u0448\u0438\u043b \u0412\u041e\u0422 \u042d\u0422\u0418\u041c\u0418 \u0420\u0423\u041a\u0410\u041c\u0418 \u0437\u0430\u043f\u0438\u043b\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0431\u0438\u043d\u0434\u0435\u0440\u2026 \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u043d\u043e\u0432\u0438\u0447\u043a\u0430\u043c \u2014 \u043d\u0430\u0432\u0435\u0440\u043d\u043e, \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0421#-\u043a\u0440\u0443\u0433\u043e\u0437\u043e\u0440\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-266877","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266877"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266877\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}