Reputation: 113
I can't bind foreground color to property...
I have this:
<TextBox Grid.Column="1" Grid.Row="1" Width="150" Margin="10,5"
IsReadOnly="True" Name="Output" FontSize="20" Foreground="{Binding Path=ForegroundColor}"/>
and:
private Brush foregroundColor;
public Brush ForegroundColor {
get { return foregroundColor; }
set {
foregroundColor = value;
OnPropertyChanged("ForegroundColor");
}
}
private void CheckBtn_Click(object sender, RoutedEventArgs e) {
if (IsPalindrome(Input.Text)) {
ForegroundColor = Brushes.Gold;
Output.Text = "Yep";
} else
Output.Text = "Nope";
}
I'm just a beginner, so it is a simple project ;) Some sources to learn from are welcome... sorry for mistakes, i'm from Ukraine
Upvotes: 4
Views: 248
Reputation: 39326
If you have defined that property in your code behind class, you can set the DataContext
of your window this way:
<Window x:Class="YourWindow"
Title="Your Title"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
After that your should be able to bind that property as your are trying to do.
Upvotes: 2