Reputation: 460
I have here 1 of 32 unnamed buttons
<Button Grid.Column="8" Content="5-1" Grid.Row="1" Click="ButtonBase_OnClick"/>
all of the 32 unnamed buttons share the same event
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
string x = sender.ToString();
x = x.Remove(0, x.Length - 3);
//sender.GetType().GetProperties()
}
what I want is to change the background color of the button I clicked. but how canI do it in C# and WPF markup?
Upvotes: 2
Views: 121
Reputation: 2460
Sender is your Button
(Object) you need to cast to Button
. Try this:
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
string senderToString = sender.ToString();
Button yourClickedButton = sender as Button;
yourClickedButton.Background = Brushes.AliceBlue ;
x = x.Remove(0, x.Length - 3);
}
Upvotes: 6