TheRealSteveJudge
Прежде всего, вы должны написать класс конвертера, например ColorConverter. cs
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
namespace WpfApplication1
{
public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is Color)) return null;
var color = (Color) value;
var solidColorBrush = new SolidColorBrush(color);
return solidColorBrush;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Затем вы должны использовать его для привязки данных фона текстового поля.
<Window x:Class="WpfApplication1.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:WpfApplication1"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:ColorConverter x:Key="ColorConverter"></local:ColorConverter>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<xctk:ColorPicker Name="ColorPicker"></xctk:ColorPicker>
<TextBox Grid.Row="1"
Background="{Binding ElementName=ColorPicker, Path=SelectedColor, Converter={StaticResource ColorConverter}}"></TextBox>
</Grid>
</Window>