title: How to write getters and setters to convert WPF dependency property?
body: <p>I am writing a user control that simulates an LED. The LED currently just has two states, but the goal is to have four (on, off, disconnected from signal, disabled). I want to be able to set the control property State to match the possible states as follows.</p>
  <pre><code>&lt;local:LEDControl State=&quot;ON&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;100&quot; Margin=&quot;374,131,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;100&quot;/&gt;
  </code></pre>
  <p>Setting this property should set the color of the LED too some predefined colors:</p>
  <pre><code> public partial class LEDControl : UserControl
      {
          private (string ON, string OFF) state_colors = (&quot;#5DC211&quot;, &quot;#FF0808&quot;);
          private string _state; 
  
          public string State
          {
              get
              {
                  return _state; 
              }
              set
              {
                  if (value == &quot;ON&quot;)
                  {
                      _state = state_colors.ON;
                  } 
                  else //should check for valid input
                  {
                      _state = state_colors.OFF; 
                  }
              }
          }
          public LEDControl()
          {
              InitializeComponent();
              this.DataContext = this;
              State = &quot;OFF&quot;;
          }
  
      }
  </code></pre>
  <p>And here is the xaml:</p>
  <pre><code>&lt;UserControl x:Class=&quot;SV3eStatusWindow.LEDControl&quot;
               xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
               xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
               xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; 
               xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; 
               xmlns:local=&quot;clr-namespace:SV3eStatusWindow&quot;
               mc:Ignorable=&quot;d&quot; 
               d:DesignHeight=&quot;45&quot; Width=&quot;44.628&quot;
               &gt;
      &lt;Grid x:Name =&quot;LayoutRoot&quot; &gt;
          &lt;Ellipse Fill=&quot;{Binding State}&quot; HorizontalAlignment=&quot;Center&quot; Height=&quot;35&quot; Stroke=&quot;Black&quot; VerticalAlignment=&quot;Center&quot; Width=&quot;35&quot;/&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  <p>I get an error saying I can only bind to a dependency property. But I am confused about how to write a dependency property to have the get and set functionality I have above.</p>
  <p>I would like to know how to do what I am trying to do above for educational purposes. However, I acknowledge that this might not be the best design because I am new to WPF and I am open to suggestion.</p>