Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7: Change Textblock Foreground color based on another Textblock's value
    primarykey
    data
    text
    <p>Say I have this XAML:</p> <pre><code>&lt;TextBlock Name="t1" Text="{Binding team1}" Foreground="White" FontSize="32" /&gt; &lt;ListBox Name="lbBooks" Width="441" Height="490" &gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate x:Name="d1" &gt; &lt;StackPanel Name="spMain"&gt; &lt;StackPanel Orientation="Horizontal" &gt; &lt;HyperlinkButton Content="{Binding BookName}" Margin="5" Width="230" TargetName="_blank" NavigateUri="{Binding BookWebsite}"/&gt; &lt;StackPanel Orientation="Vertical" HorizontalAlignment="Right" Margin="0,0,0,0" &gt; &lt;TextBlock Name="b1" Text="{Binding BookLine1}" Margin="5" Width="160" HorizontalAlignment="Right"&gt;&lt;/TextBlock&gt; &lt;TextBlock Name="b1U" Text="{Binding BookLine2}" Margin="5" Width="160" Foreground="Wheat" HorizontalAlignment="Right"&gt;&lt;/TextBlock&gt; &lt;TextBlock Name="b3" Text="{Binding BookLine3}" Margin="5" Width="160" DataContext="{Binding team1,Converter={StaticResource tbConverter}, ElementName=b3, Mode=TwoWay}" HorizontalAlignment="Right"&gt;&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>I want to change the foreground color of the TextBlock named "b3" depending on the value of TextBlock "t1". I know I need to implement a converter kind of like the one below:</p> <pre><code>public class TBConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { //do I need to check against the Textblock t1 value in here? if (value != null &amp;&amp; t1.Text == "Text that triggers change" ) { //need code to change Textblock foreground color } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>So,(1) what is the code I need in the converter to change the foreground color of the Textblock b3? And (2), am I calling the converter correctly in the datacontext of Textblock "b3"? Thank you!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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