Buttons are made programmatically containing each text string. Maybe, there're some ways to find a control with its property like this case.
Here is my code which to make buttons programmatically and a code of linked event.
What if an user press A button(Airplane), the color of button become yellow. However, what if the user press B button(Car) just after pressing A button? I want to know how to change the color of A button from yellow to back normal and the color of B button from normal to yellow. This is why I need to indicate a button with its content.
for (int k = 0; k < Overviews.Length; k++)
{
Button btnoverviewcontent = new Button();
ToolTip tt = new ToolTip();
tt.Content = "Press button if you want to modify or delete";
btnoverviewcontent.ToolTip = tt;
btnoverviewcontent.Cursor = Cursors.Hand;
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 101, 173, 241);
btnoverviewcontent.Background = mySolidColorBrush;
btnoverviewcontent.Effect = new DropShadowEffect
{
Color = new Color { A = 255, R = 0, G = 0, B = 0 },
Direction = 315,
ShadowDepth = 5,
Opacity = 1
};
btnoverviewcontent.Padding = new Thickness(3, 3, 3, 3);
btnoverviewcontent.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
TextBlock textBlock = new TextBlock()
{
Text = Overviews[k],
TextAlignment = TextAlignment.Left,
TextWrapping = TextWrapping.Wrap,
};
btnoverviewcontent.Content = textBlock;
btnoverviewcontent.BorderThickness = new Thickness(0, 0, 0, 0);
btnoverviewcontent.FontStretch = FontStretches.UltraExpanded;
btnoverviewcontent.Margin = new Thickness(5, 5, 5, 5);
WrapPanelGreen.Children.Add(btnoverviewcontent);
btnoverviewcontent.Click += new RoutedEventHandler(OnOverviewClick);
}
void OnOverviewClick(object sender, RoutedEventArgs args)
{
buttonOverviewmodification.Visibility = Visibility.Visible;
buttonOverviewdeletion.Visibility = Visibility.Visible;
Button btn = (Button)sender;
DoubleAnimation animation = new DoubleAnimation(1, TimeSpan.FromMilliseconds(350));
buttonOverviewmodification.BeginAnimation(Image.OpacityProperty, animation);
buttonOverviewdeletion.BeginAnimation(Image.OpacityProperty, animation);
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 253, 253, 10);
(sender as Button).Background = mySolidColorBrush;
}