I'm trying to set the Background Property of an in-code generated label to a custom object property. Well this code don't work. The label appear correctly but the background property is a null value. Where I'm wrong?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Something s = new Something();
Label testLabel = new()
{
Content = "TEST",
Margin = new Thickness(5),
Padding = new Thickness(5)
};
Binding binding = new("Background");
binding.Source = s.Background;
testLabel.SetBinding(BackgroundProperty, binding);
stackpanel.Children.Add(testLabel);
}
}
public class Something
{
private Brush _background = Brushes.Green;
public Brush Background
{
get { return _background; }
set { _background = value; }
}
}