Last active
December 17, 2015 18:29
-
-
Save jhalbrecht/5653797 to your computer and use it in GitHub Desktop.
This ValueConverter expects a string of either "Heads" or "Tails" and returns Green or Red respectively or yellow as a default or unknown value. I use it in a Windows Store Application, "Decisive" to color the text result of a coin toss. I've been using a long weekend as a sprint to focus on learning VS2012 and blend design tools. Blend made it …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Windows.UI; | |
using Windows.UI.Xaml.Data; | |
using Windows.UI.Xaml.Media; | |
namespace Decisive.Common | |
{ | |
public sealed class HeadsOrTailsToColorConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, string language) | |
{ | |
switch (value as string) | |
{ | |
case "Heads": | |
return new SolidColorBrush(Colors.Green); | |
case "Tails": | |
return new SolidColorBrush(Colors.Red); | |
default: | |
return new SolidColorBrush(Colors.Yellow); | |
} | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, string language) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page.Resources> | |
<uncommon:HeadsOrTailsToColorConverter x:Key="TextToColor" /> | |
</Page.Resources> | |
<TextBlock x:Name="textBlockYeaNoAnswer" | |
Grid.Column="0" | |
Grid.Row="1" | |
HorizontalAlignment="Center" | |
VerticalAlignment="Center" | |
Text="{Binding YeaNoAnswer}" | |
FontSize="56" | |
Foreground="{Binding Text, Converter={StaticResource TextToColor}, RelativeSource={RelativeSource Mode=Self}}" | |
FontWeight="Bold" /> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment