Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're on the right track with the MultiBinding. The key is to use a MultiValueCoverter in conjunction with the MultiBinding.</p> <pre><code>&lt;MultiBinding Converter="{StaticResource Coverter_LocationMultiConverter}" Mode="OneWayToSource"&gt; &lt;Binding Source="{StaticResource DevianceProvider}" Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource" /&gt; &lt;Binding Source="{StaticResource CommentProvider}" Path="MethodParameters[0]" BindsDirectlyToSource="True" Mode="OneWayToSource" /&gt; &lt;/MultiBinding&gt; </code></pre> <p>Where we were binding to just one thing before, now we are binding it to both ObjectDataProviders. The key factor that lets us do this is the converter:</p> <pre><code>public class LocationMultiCoverter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { return new object[] { value, value }; } #endregion } </code></pre> <p>Because we just need the same value in both places the CovertBack method is quite simple, however I'm sure you can see that it could be used to parse some complex stuff and pass back different components to different places in the UI. </p> <p>Using this converter we can also try out a small sample, using two text boxes instead:</p> <pre><code>&lt;Window x:Class="Sample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Sample" Title="Window1" Height="300" Width="300"&gt; &lt;Window.Resources&gt; &lt;local:LocationMultiCoverter x:Key="Coverter_LocationMultiConverter" /&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;StackPanel&gt; &lt;TextBlock x:Name="uiDeviance" /&gt; &lt;TextBlock x:Name="uiComment" /&gt; &lt;ComboBox x:Name="uiLocations" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedValuePath="Content"&gt; &lt;ComboBoxItem&gt;1&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;2&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;3&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;4&lt;/ComboBoxItem&gt; &lt;ComboBoxItem&gt;5&lt;/ComboBoxItem&gt; &lt;ComboBox.SelectedValue&gt; &lt;MultiBinding Converter="{StaticResource Coverter_LocationMultiConverter}" Mode="OneWayToSource"&gt; &lt;Binding ElementName="uiDeviance" Path="Text" BindsDirectlyToSource="True" /&gt; &lt;Binding ElementName="uiComment" Path="Text" BindsDirectlyToSource="True" /&gt; &lt;/MultiBinding&gt; &lt;/ComboBox.SelectedValue&gt; &lt;/ComboBox&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>(The Converter in my example exists in the Window's code behind as a separate class) And as you can see testing this out it will update both TextBoxes when the SelectedValue changes.</p>
 

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