<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic EditBox Text Property in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/editbox-text-property/m-p/1568122#M12412</link>
    <description>&lt;P&gt;How can you push a string to the EditBox control from say a button control.&amp;nbsp; For instance, i would like to click on a button in the addin ribbon that would send a string to the EditBox text property.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2024 21:04:01 GMT</pubDate>
    <dc:creator>mstranovsky</dc:creator>
    <dc:date>2024-12-12T21:04:01Z</dc:date>
    <item>
      <title>EditBox Text Property</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/editbox-text-property/m-p/1568122#M12412</link>
      <description>&lt;P&gt;How can you push a string to the EditBox control from say a button control.&amp;nbsp; For instance, i would like to click on a button in the addin ribbon that would send a string to the EditBox text property.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 21:04:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/editbox-text-property/m-p/1568122#M12412</guid>
      <dc:creator>mstranovsky</dc:creator>
      <dc:date>2024-12-12T21:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: EditBox Text Property</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/editbox-text-property/m-p/1568264#M12413</link>
      <description>&lt;P&gt;Here are two ways to do it. One uses an event which keeps the button and edit box loosely coupled, the other uses a direct reference where the button updates the edit box directly. The loosely coupled is the most flexible but is a bit more work than simply updating the edit box text - and, if that is literally all u need, then its overkill.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="button_and_editbox.png" style="width: 343px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/121678i119631AA80C088D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="button_and_editbox.png" alt="button_and_editbox.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;public class DateTimeStringChangedEventArgs : EventBase
{
  public string OldDateTimeString { get; private set; }
  public string NewDateTimeString { get; private set; }

  public DateTimeStringChangedEventArgs(string oldDateTimeString, string newDateTimeString)
  {
    OldDateTimeString = oldDateTimeString;
    NewDateTimeString = newDateTimeString;
  }
}

public class DateTimeStringChangedEvent : 
  CompositePresentationEvent&amp;lt;DateTimeStringChangedEventArgs&amp;gt;
{

  public static SubscriptionToken Subscribe(
    Action&amp;lt;DateTimeStringChangedEventArgs&amp;gt; action, bool keepSubscriberReferenceAlive = false)
  {
    return FrameworkApplication.EventAggregator.GetEvent&amp;lt;DateTimeStringChangedEvent&amp;gt;()
        .Register(action, keepSubscriberReferenceAlive);
  }

  public static void Unsubscribe(Action&amp;lt;DateTimeStringChangedEventArgs&amp;gt; subscriber)
  {
    FrameworkApplication.EventAggregator.GetEvent&amp;lt;DateTimeStringChangedEvent&amp;gt;()
      .Unregister(subscriber);
  }

  public static void Unsubscribe(SubscriptionToken token)
  {
    FrameworkApplication.EventAggregator.GetEvent&amp;lt;DateTimeStringChangedEvent&amp;gt;()
      .Unregister(token);
  }

  internal static void Publish(DateTimeStringChangedEventArgs payload)
  {
    FrameworkApplication.EventAggregator.GetEvent&amp;lt;DateTimeStringChangedEvent&amp;gt;()
       .Broadcast(payload);
  }
}

internal class Module1 : Module
{
  private static Module1 _this = null;

  private string _dateTimeString = 
    DateTime.Now.ToString("G", CultureInfo.CurrentCulture);

  public string DateTimeString
  {
    get
    {
       return _dateTimeString;
    }
    set
    {
      var args = new DateTimeStringChangedEventArgs(
                       _dateTimeString, value);
      _dateTimeString = value;
      //Raise the event
      DateTimeStringChangedEvent.Publish(args);
    }
  }

  public EditBoxDirectApproach EditBoxDirectApproach { get; set; } = null;

  ...
}

internal class Button1 : Button
{
  protected override void OnClick()
  {
    var date_string = DateTime.Now.ToString("G", CultureInfo.CurrentCulture);
    //Indirect, loose-coupling
    Module1.Current.DateTimeString = date_string;

    //Direct, direct-coupled
    Module1.Current.EditBoxDirectApproach.Text = date_string;
  }
}


internal class EditBoxIndirectApproach : EditBox
{
  public EditBoxIndirectApproach()
  {
    Initialize();
  }

  private bool _ignoreEvents = false;

  private void Initialize()
  {
    //This will invoke OnTextChange which is ok
    //as we havent subscribed to the event yet
    this.Text = Module1.Current.DateTimeString;

    DateTimeStringChangedEvent.Subscribe((args) =&amp;gt;
    {
      _ignoreEvents = true;
      try
      {
        //Invokes OnTextChange 
        this.Text = args.NewDateTimeString;
      }
      finally
      {
        _ignoreEvents = false;
      }
    });
  }

  protected override void OnTextChange(string text)
  {
    //prevent (infinite) recursion
    if (_ignoreEvents)
      return;

    Module1.Current.DateTimeString = text;
    base.OnTextChange(text);
  }
}

internal class EditBoxDirectApproach : EditBox
{
  public EditBoxDirectApproach()
  {
    Module1.Current.EditBoxDirectApproach = this;
    this.Text = DateTime.Now.ToString("G", CultureInfo.CurrentCulture);
  }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 00:21:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/editbox-text-property/m-p/1568264#M12413</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2024-12-13T00:21:44Z</dc:date>
    </item>
  </channel>
</rss>

