Im adding a list of buttons in code and also subscribing to their mouseleave event. For each button i subcribe to the event with an anonymous function, the problem is that when I run the app they are all subscribed to the last anonymous function. Here is the code, I hope I explained myself.
var modules = ModulesSC.GetAllMoudules();
var imageSet = ModulesSC.GetModuleImageSet();
foreach (var module in modules)
{
var btn = new Button();
btn.SetResourceReference(Control.TemplateProperty, "SideMenuButton");
btn.Content = module.Title;
btn.MouseEnter += (s, e) => { ShowInfo(module.Description); };
btn.MouseLeave += (s, e) => { HideInfo(); };
ModuleButtons.Children.Add(btn);
}
protected void HideInfo()
{
DescriptionLabel.Visibility = Visibility.Collapsed;
DescriptionText.Text = string.Empty;
}
protected void ShowInfo(string description)
{
DescriptionLabel.Visibility = Visibility.Visible;
DescriptionText.Text = description;
}
When i run the app they all call showInfo with the las "module.Description"
Thanks -Alejandro