title: Binding in xaml with a parameterized contructor
body: <p>I'm currently trying to bind to data from a class with a parameterized constructor and I'm having trouble figuring out how to get xaml to use that constructor instead of the default one. What I want to do is have the <code>Value</code> property of my <code>Gauge Control</code> be set to equal the number of entries returned by my <code>IMobileServiceTableQuery</code> shown in the <code>GetDoDo method</code>.</p>
  
  <p>My viewmodel class <code>StatsViewModel</code> looks like this:</p>
  
  <pre><code>class StatsViewModel : BindableBase
  {
      private int _value;
  
      // Default constructor
      public StatsViewModel() { }
  
      public StatsViewModel(int val)
      {
          _value = val;
      }
  
      public int Value {
          get { return _value; }
          set { this.SetProperty(ref _value, value); }
      }
  }
  </code></pre>
  
  <p>Then in my xaml.cs file I have a <code>GetToDo</code> method which queries a table in Azure and sets the Value property in the viewmodel to equal the number of rows returned by the query:</p>
  
  <pre><code>private async void GetTodo()
  {
      ImobileServiceTableQuery&lt;int&gt; query = taskTable
          .Where(t =&gt; t.Status == 1)
          .Select(t =&gt; t.Status);
  
      List&lt;int&gt; statusOne = await query.ToListAsync();
  
      int val = statusOne.Count;
  
      StatsViewModel stats = new StatsViewModel(val);
  
      /******************************************************************************
       * This is something I tried earlier but it didn't
       * work so I commented it out:
       *
       * Binding valueBinding = new Binding();
       * valueBinding.Source = stats;
       * BindingOperations.SetBinding(ToDoGauge, Gauge.ValueProperty, valueBinding);
       *
       * Was I on the right track here?
       *******************************************************************************/
  }
  </code></pre>
  
  <p>Finally the relevant code in my xaml looks like this:</p>
  
  <pre><code>&lt;Page.Resources&gt;
      ...
      &lt;viewmodels:StatsViewModel x:Name="StatsViewModel" /&gt;
  &lt;/Page.Resources&gt;
  
  ...
  
  &lt;StackPanel&gt;
      &lt;TextBlock Text="To Do Items:" Style="{StaticResource HeaderTextBlockStyle}"/&gt;
      &lt;controls:Gauge
          x:Name="ToDoGauge"
          Minimum="0"
          Maximum="100"
          Height="200"
          Value="{Binding Value}"
          Unit="To Do" FontFamily="Global User Interface" /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>I'm pretty sure the issue has to do with the fact that the constructor is parameterized, because when I stepped through the code I was able to verify that the number of items in the list I query in <code>GetToDo()</code> gets assigned accurately to <code>_value</code> in <code>StatsViewModel</code>. My thinking is that the xaml code just looks at the default constructor, see's that nothing is defined there and assumes Value is an empty value. What I don't understand is how to get the xaml code to see the value of _value set in the parameterized constructor.</p>
  
  <p>Thanks in advance to anyone who can help.</p>