Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that when you specify your Gradient stops in code you are not specifying the offset.</p> <p>However I would suggest the you not avoid Xaml for a solution. First read this blog: <a href="http://geekswithblogs.net/codingbloke/archive/2010/05/28/a-generic-boolean-value-converter.aspx" rel="nofollow">A Generic Boolean Value Converter</a>. I would also suggest that your Hightlight property ought to be a <code>bool</code> type not an int.</p> <p>By including the converter code from the blog in your project you should be in a position to do something like this:-</p> <pre><code>&lt;Grid x:Name="LayoutRoot"&gt; &lt;Grid.Resources&gt; &lt;local:BoolToBrushConverter x:Key="Highlighter"&gt; &lt;local:BoolToBrushConverter.TrueValue&gt; &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,1"&gt; &lt;GradientStopCollection&gt; &lt;GradientStop Color="#4cffffcc" Offset="0" /&gt; &lt;GradientStop Color="#ffffffcc" Offset="1" /&gt; &lt;/GradientStopCollection&gt; &lt;/LinearGradientBrush&gt; &lt;/local:BoolToBrushConverter.TrueValue&gt; &lt;local:BoolToBrushConverter.FalseValue&gt; &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,1"&gt; &lt;GradientStopCollection&gt; &lt;GradientStop Color="#4ce6e6e6" Offset="0" /&gt; &lt;GradientStop Color="#ffe6e6e6" Offset="1" /&gt; &lt;/GradientStopCollection&gt; &lt;/LinearGradientBrush&gt; &lt;/local:BoolToBrushConverter.FalseValue&gt; &lt;/local:BoolToBrushConverter&gt; &lt;/Grid.Resources&gt; &lt;ListBox Name="lstResults" ItemContainerStyle="{StaticResource ListBoxItemStyle1}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Background="{Binding highlight, Converter={StaticResource Highlighter}}"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding name}" TextWrapping="Wrap" FontSize="24" FontWeight="Bold" Foreground="Black"/&gt; &lt;TextBlock Text="{Binding address}" TextWrapping="Wrap" FontSize="24" Foreground="Black" /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>Not only does this approach allow you to keep the visual description in the more familiar Xaml fashion, its much more flexiable and resuable.</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