private void Color_Checked(object sender, EventArgs e)
{
RadioButton rb = sender as RadioButton;
if (rb == null || !rb.IsChecked != true) return;
Dictionary<string, System.Windows.Media.Brush> colors =
new Dictionary<string, System.Windows.Media.Brush>
{
{"Красный", System.Windows.Media.Brushes.Red},
{"Синий", System.Windows.Media.Brushes.Blue},
{"Зелёный", System.Windows.Media.Brushes.Green},
{"Жёлтый", System.Windows.Media.Brushes.Yellow},
{"Оранжевый", System.Windows.Media.Brushes.Orange},
{"Фиолетовый", System.Windows.Media.Brushes.Purple},
{"Розовый", System.Windows.Media.Brushes.Pink},
{"Чёрный", System.Windows.Media.Brushes.Black},
{"Серый", System.Windows.Media.Brushes.Gray},
{"Коричневый", System.Windows.Media.Brushes.Brown}
};
if (colors.ContainsKey(rb.Content.ToString()))
tbSample.Foreground = colors[rb.Content.ToString()];
}
}
}
<StackPanel>
<TextBlock Text="Выберите цвет:" x:Name="tbSample" FontSize="14" Margin="0,20,0,15"></TextBlock>
<RadioButton Content="Красный" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Синий" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Зелёный" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Жёлтый" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Оранжевый" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Фиолетовый" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Розовый" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Чёрный" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Серый" GroupName="Color" Click="Color_Checked"/>
<RadioButton Content="Коричневый" GroupName="Color" Click="Color_Checked"/>
</StackPanel>