I am not sure if I fully understood what needs to happen, if you want to change the foreground of Label you could try to refer to the code below.
The MouseLeftButtonDown event of the Label changes the foreground of the clicked Label. If I misunderstood what you mean, please point it out and let me know .
The code of xaml is as follows:
<StackPanel>
<Label Name="Label1" Height="30" Content="Label1" MouseLeftButtonDown="Button_Click" Foreground="{Binding changeColor}"> </Label>
<Label Name="Label2" Height="30" Content=" Label2" MouseLeftButtonDown="Button_Click" Foreground="{Binding changeColor}" > </Label>
</StackPanel>
The code of xaml.cs is as follows:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace ChangeLabelForegroundColorBindCommand
{
public partial class MainWindow : Window
{
public string changeColor { get; set; }
public MainWindow()
{
InitializeComponent();
changeColor = "gray";
DataContext = this;
}
private void Button_Click(object sender, MouseButtonEventArgs e)
{
Label label = sender as Label;
label.Foreground = Brushes.Blue;
MessageBox.Show(label + " is clicked");
label.Foreground = Brushes.Gray;
}
}
}
The result is shown in the figure: