Note that there are some explanatory texts on larger screens.

plurals
  1. POMultibinding: two colums to one column
    primarykey
    data
    text
    <p>I have a table which has two columns <code>ValueA</code> and <code>ValueB</code>. I need to show the table in a grid, but I need to show either <code>ValueA</code> or <code>ValueB</code>, but not both. So if <code>ValueA</code> doesn't have a value, then <code>ValueB</code> is shown and vice versa. When user enters a value to the column, only <code>ValueA</code> should be updated. So <code>ValueB</code> in kind of a default value (it's update in another part of the program).</p> <p>I've tried to resolve this problem using <code>MultiBinding</code>, but I've only managed to <em>show</em> the values. The value user enters to the grid always gets overwritten by the original value.</p> <p>I have created a converter named <code>ValueAValueBConverter</code> that has a Convert method like this:</p> <pre><code>public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values[0] != DependencyProperty.UnsetValue &amp;&amp; values[0] != null &amp;&amp; !string.IsNullOrEmpty(values[0].ToString())) { Debug.WriteLine("values 0: " + values[0]); return values[0].ToString(); } if (values[1] != DependencyProperty.UnsetValue &amp;&amp; values[1] != null &amp;&amp; !string.IsNullOrEmpty(values[1].ToString())) { Debug.WriteLine("values 1: " + values[1]); return values[1].ToString(); } return null; } </code></pre> <p>And a ConvertBack method (which never gets called):</p> <pre><code>public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { return new object [] { value, value }; } </code></pre> <p>The XAML of the bound colums looks like this:</p> <pre><code>&lt;toolkit:DataGridTextColumn Width="2*" Header="{x:Static localProperties:Resources.TValuesAB}"&gt; &lt;toolkit:DataGridTextColumn.Binding&gt; &lt;MultiBinding Converter="{StaticResource myValueAValueBConverter}" Mode="TwoWay"&gt; &lt;Binding Path="ValueA" UpdateSourceTrigger="PropertyChanged" /&gt; &lt;Binding Path="ValueB" UpdateSourceTrigger="PropertyChanged" /&gt; &lt;/MultiBinding&gt; &lt;/toolkit:DataGridTextColumn.Binding&gt; &lt;/toolkit:DataGridTextColumn&gt; </code></pre> <p>Should I do this in the ViewModel (we're using MVVM pattern) or is there any other way to do this with XAML?</p>
    singulars
    1. This table or related slice is empty.
    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. 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