Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok I've wrote some code, but you might not like it :)</p> <pre><code>public class DataChangedEventArgs : EventArgs { public string Data { get; set; } public DataChangedEventArgs(string data) { Data = data; } } public delegate void DataChangedEventHander(DataChangedEventArgs e); public class BackEnd { public event DataChangedEventHander OnDataChanged; private string _data; public string Data { get { return _data; } set { _data = value; RaiseOnDataChanged(); } } private static readonly object _sync = new object(); private static BackEnd _instance; public static BackEnd Current { get { lock (_sync) { if (_instance == null) _instance = new BackEnd(); return _instance; } } } private void RaiseOnDataChanged() { if(OnDataChanged != null) OnDataChanged(new DataChangedEventArgs(Data)); } } public class ConsumerControl { public event EventHandler OnTextChanged; private string _text; public string Text { get { return _text; } set { _text = value; if (OnTextChanged != null) OnTextChanged(this, EventArgs.Empty); } } } public class Consumer { public ConsumerControl Control { get; set; } public Consumer() { Control = new ConsumerControl(); BackEnd.Current.OnDataChanged += NotifyConsumer; Control.OnTextChanged += OnTextBoxDataChanged; } private void OnTextBoxDataChanged(object sender, EventArgs e) { NotifyBackEnd(); } private void NotifyConsumer(DataChangedEventArgs e) { Control.Text = e.Data; } private void NotifyBackEnd() { // unsubscribe BackEnd.Current.OnDataChanged -= NotifyConsumer; BackEnd.Current.Data = Control.Text; // subscribe again BackEnd.Current.OnDataChanged += NotifyConsumer; } } public class BackEndTest { public void Run() { var c1 = new Consumer(); var c2 = new Consumer(); c1.Control.Text = "1"; BackEnd.Current.Data = "2"; } } </code></pre> <p>The main idia is here:</p> <pre><code>// unsubscribe BackEnd.Current.OnDataChanged -= NotifyConsumer; BackEnd.Current.Data = Control.Text; // subscribe again BackEnd.Current.OnDataChanged += NotifyConsumer; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload