我想在属性中设置颜色,并使用该属性绑定到窗口的背景颜色。 即属性中设置的值将绑定到我的窗口背景。
以下代码对我不起作用。
类
public static class configclas
{
public static int UserId { get; set; }
public static string UserName { get; set; }
private static string _klant;
public static String Klant
{
get { return _klant; }
set { _klant = value; }
}
}
XAML
<Window x:Class="SmartAccount.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfTool="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
Title="Test" Height="300" Width="300">
<Grid x:Name="setcolor" Background="{Binding Klant}">
<wpfTool:ColorPicker x:Name="colorPicker" Width="40" Height="30" Canvas.Left="3" Visibility="Visible" Canvas.Top="208"></wpfTool:ColorPicker>
<Button x:Name="btnsubmit" Height="30" Width="50" Content="submit" Margin="0,90,0,0" Click="btnsubmit_Click_1"></Button>
</Grid>
</Window>
test.xaml.cs
private void btnsubmit_Click_1(object sender, RoutedEventArgs e)
{
var clrr = colorPicker.SelectedColor.ToString();
BrushConverter bc = new BrushConverter();
var bgcolor = (System.Windows.Media.Brush)bc.ConvertFrom(colorPicker.SelectedColor.ToString());
configclas.Klant = clrr;
}
}