title: F# Creating a UserControl Programmatically: Missing Update (keyboard input seem locked)
body: <p>I have tried to create a "UserControl" "By-Code" only, using F# (Vers. 12.0.30815.0 + Framework 4.5) since I prefer this "way" (no mix between C# and F#).</p>
  
  <p>NOTE: I have to show multiple properties of a single Class in an Input Form, so this UserControl need to implement Binding capabilities to connect the "output" to the Class's Properties.</p>
  
  <p>I tried to modify the numeric values inside the window (i.e. 1200 or 400) or moving the focus between the controls using the TAB key located on the keyboard, but everiting seem locked. </p>
  
  <p>No update of the numerical value can be achieved. I can only delete one or more single figures, without any updates.</p>
  
  <p>Perhaphs there is a conceptual error inside the Event "dataChangedEvent" that I have implemented  inside the UserControls (i.e. "Data" property of the "ucData" Control - see the Code). It is something like: "INotifyPropertyChanged".</p>
  
  <p>NOTE: perhaphs this error in the implementation of the Event is also present with the "Description" and "UnitOfMeasure" Porperties of the UserControl. </p>
  
  <p>Can somebody can hel me to discover where is/are my error/erros in the here below reported Lines of Codes?</p>
  
  <p>many Thanks in advance.</p>
  
  <p>ANN</p>
  
  <h1>DEFINE THE USER CONTROL</h1>
  
  <pre><code>type ucData() as this =
      inherit Windows.Controls.UserControl()
  
      static let  OnDataPropertyChanged (sender:DependencyObject) (e:DependencyPropertyChangedEventArgs) =
          let control = unbox&lt;ucData&gt;(sender)
          let newValue = unbox&lt;double&gt;(e.NewValue)
          let oldValue = unbox&lt;double&gt;(e.OldValue)
          System.Console.WriteLine
              (sprintf 
                  "&gt;&gt;&gt; OnPropertyChanged 'ucData':'Data': Control Name: %s; Value: %f --&gt; %f &lt;&lt;&lt;" 
                  control.Name oldValue newValue )
          let argsEvent = new RoutedPropertyChangedEventArgs&lt;double&gt;(oldValue, newValue)
          argsEvent.RoutedEvent &lt;- ucData.DataChangedEvent  // I get an ERROR here!!!!
          control.RaiseEvent(argsEvent)
  
  
      static let OnCoerceDataProperty (sender:DependencyObject) (data:obj) =
          let control = unbox&lt;ucData&gt;(sender)
          let value = unbox&lt;double&gt;(data)
          System.Console.WriteLine
              (sprintf 
                  "&gt;&gt;&gt; OnCoerceValue 'ucData':'Data': Control Name: %s; Value: : %f &lt;&lt;&lt;" 
                  control.Name value )
          box(value)
  
      static let OnValidateDataProperty (data:obj) =
          System.Console.WriteLine
              (sprintf 
                  "&gt;&gt;&gt; OnValidateValue 'ucData':'Data': Data %s &lt;&lt;&lt;" 
                  (data.ToString()) )
          data.GetType() = typeof&lt;double&gt;
  
      static let dpData = 
          DependencyProperty.Register("Data",typeof&lt;double&gt;, typeof&lt;ucData&gt;, 
              new FrameworkPropertyMetadata( 0.0,
                  FrameworkPropertyMetadataOptions.Inherits,
                  new PropertyChangedCallback(OnDataPropertyChanged),
                  new CoerceValueCallback(OnCoerceDataProperty) ),
              new ValidateValueCallback(OnValidateDataProperty) )
  
      static let reDataChangedEvent =
          EventManager.RegisterRoutedEvent
              ("DataChanged", RoutingStrategy.Bubble, 
                  typeof&lt;RoutedPropertyChangedEventHandler&lt;double&gt;&gt;, typeof&lt;ucData&gt;)
  
      let dataChangedEvent = 
          let e = new  Event&lt;RoutedPropertyChangedEventHandler&lt;double&gt;,RoutedPropertyChangedEventArgs&lt;double&gt;&gt;() 
          // Equialent to: 
          //    public event RoutedPropertyChangedEventHandler&lt;double&gt; DataChanged
          //    {
          //       add { AddHandler(DataChangedEvent, value); }
          //       remove { RemoveHandler(DataChangedEvent, value); }
          //    }
          // where DataChangedEvent is so defined:
          //    public static readonly RoutedEvent DataChangedEvent;        
          e
  
      let grid = 
          let c = new Grid()
          let colData = new ColumnDefinition()
          colData.MinWidth &lt;- 70.
          c.ColumnDefinitions.Add( colData )
          c
  
      let data= 
          let c = new TextBox()
          c.Margin&lt;- new Thickness(3.0)
          c.SetValue(Grid.ColumnProperty,1)
          c
  
      do        
  
          grid.Children.Add(data) |&gt; ignore
          this.AddChild(grid) |&gt; ignore
  
          let bData = new Binding()
          bData.Path &lt;- new PropertyPath("Data")
          bData.StringFormat &lt;- "N"
          bData.ConverterCulture &lt;- System.Globalization.CultureInfo.InvariantCulture
          bData.Mode &lt;- BindingMode.TwoWay 
          bData.RelativeSource &lt;- new RelativeSource(RelativeSourceMode.FindAncestor,typeof&lt;ucData&gt;,1)
  
          data.SetBinding(TextBox.TextProperty, bData) |&gt; ignore
  
      static member DataProperty = dpData
  
      [&lt;Description("Specify the Numerical Data"); Category("UserData")&gt;]
      member x.Data
          with get() = 
              let res = x.GetValue(ucData.DataProperty) 
              (res :?&gt; double)
          and set (v:double) = 
              x.SetValue(ucData.DataProperty, v )
  
      [&lt;CLIEvent&gt;]
      static member DataChangedEvent with get() = reDataChangedEvent   // I get an ERROR here!!!
  
      [&lt;CLIEvent&gt;]
      member x.DataChanged = dataChangedEvent.Publish 
  </code></pre>
  
  <h1>CREATE THE WINDOW</h1>
  
  <pre><code>    type TestWindow() as this =
          inherit Window()
  
      let c1 = new ucData()   
      let c2 = new ucData()   
  
      do
          c1.Name &lt;- "Data1"
          c2.Name &lt;- "Data2"
  
          this.Width &lt;- 300.
          this.Height &lt;- 300.
  
          let sp = new StackPanel()
  
          c1.Data &lt;- 1200.
          c2.Data &lt;- 400.
  
          sp.Children.Add(c1) |&gt; ignore
          sp.Children.Add(c2) |&gt; ignore
  
          c1.DataChanged.Add( fun args -&gt;
              MessageBox.Show("The button labeled \"" + c1.Data.ToString()) |&gt;ignore )
  
          c2.DataChanged.Add( fun args -&gt;
              MessageBox.Show("The button labeled \"" + c1.Data.ToString()) |&gt;ignore )
  
          this.Content &lt;- sp
  </code></pre>
  
  <h1>RUN THE TEST WINDOW</h1>
  
  <pre><code>let w = new TestWindow()
  w.Show()
  </code></pre>