Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create a converter that implements IMultiValueConverter. It might look something like this:</p> <pre><code>class AverageConverter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int total = 0; int number = 0; foreach (object o in values) { int i; bool parsed = int.TryParse(o.ToString(), out i); if (parsed) { total += i; number++; } } if (number == 0) return 0; return (total/number).ToString(); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } </code></pre> <p>A multivalue converter receives an object array, one for each of the bindings. You can process these however you need, depending on whether you're intending it for double or int or whatever.</p> <p>If the two textboxes are databound, you can use the same bindings in the multibinding for your textblock (remembering to notify when the property changes so that your average is updated), or you can get the text value by referring to the textboxes by ElementName.</p> <pre><code>&lt;TextBox Text="{Binding Value1}" x:Name="TextBox1" /&gt; &lt;TextBox Text="{Binding Value2}" x:Name="TextBox2" /&gt; &lt;TextBlock&gt; &lt;TextBlock.Text&gt; &lt;MultiBinding Converter="{StaticResource AverageConverter}"&gt; &lt;Binding ElementName="TextBox1" Path="Text" /&gt; &lt;Binding ElementName="TextBox2" Path="Text" /&gt; &lt;!-- OR --&gt; &lt;!-- &lt;Binding Path="Value1" /&gt; --&gt; &lt;!-- &lt;Binding Path="Value2" /&gt; --&gt; &lt;/MultiBinding&gt; &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; </code></pre>
    singulars
    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. 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.
    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