Skip to content

Instantly share code, notes, and snippets.

@milleniumbug
Last active July 25, 2016 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milleniumbug/bf5be826d63d8b382f7349711ceb340a to your computer and use it in GitHub Desktop.
Save milleniumbug/bf5be826d63d8b382f7349711ceb340a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace Katas
{
class BoolToColorConverter : IValueConverter
{
public static readonly BoolToColorConverter Default = new BoolToColorConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool) value ? Brushes.Blue : Brushes.HotPink;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
<Window x:Class="Katas.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Katas"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" DataContext="{Binding Source={RelativeSource Self}}">
<Grid Background="{Binding IsChecked, ElementName=CheckBox, Converter={x:Static local:BoolToColorConverter.Default}}">
<CheckBox x:Name="CheckBox" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment