Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yeap, approach to solve this problem using IValueConverter is correct and I often use it. But in your case I propose to use only <strong>declarative approach</strong>, because additional converters are additional abstraction in your solution and to understand this logic other programmer must overlook 2 files: declarative and converter implementation. And the colors, which will be switched, are identified in converter :( but not in declarative part. To avoid this, use Microsoft.Expression.Interactions and System.Windows.Interactivity from Blend SDK. Sample code:</p> <blockquote> <p>&lt; Grid x:Name="LayoutRoot" Background="White"></p> </blockquote> <pre><code> &lt; i:Interaction.Triggers&gt; &lt; c:DataTrigger Binding="{Binding BooleanFlagFromViewModel}" Comparison="Equal" Value="True"&gt; &lt; c:ChangePropertyAction TargetName="LayoutRoot" PropertyName="Background" Value="#345678" /&gt; &lt; /c:DataTrigger&gt; &lt; /i:Interaction.Triggers&gt; &lt; /Grid&gt; </code></pre> <p>Hope it helps! Good luck!</p> <p><strong>Update</strong></p> <p>As I write in comment to AnthonyWJones to avoid of accessing to binding resource by Key, I advice to use TriggerAction.</p> <p>1) TriggerAction code:</p> <blockquote> <p>[ContentProperty("Binding")]</p> <pre><code>public class ApplyBindingToDataGridRowAction : TriggerAction&lt;DataGrid&gt; { protected override void Invoke(object parameter) { DataGridRowEventArgs e = (DataGridRowEventArgs) parameter; e.Row.SetBinding(DataGridRow.BackgroundProperty, Binding); } public Binding Binding { get; set; } } </code></pre> </blockquote> <p>2) Use in XAML:</p> <blockquote> <p>&lt; DataGrid ...></p> <p>&lt; i:Interaction.Triggers></p> <pre><code> &lt; i:EventTrigger EventName="LoadingRow"&gt; &lt; a:ApplyBindingToDataGridRowAction&gt; &lt; Binding Path="Is" Converter="{StaticResource Highlighter}"/&gt; &lt; /a:ApplyBindingToDataGridRowAction&gt; &lt; /i:EventTrigger&gt; &lt; /i:Interaction.Triggers&gt; </code></pre> <p>&lt; /DataGrid></p> </blockquote>
 

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