I want to make an extension method which fills a stackpanel with buttons.
In order to do this I have to pass in a mouse-click-handler.
What type does the mouseClickHandler
parameter have to be here?
I know it's something like these but they all don't work:
delegate
Func<object, RoutedEventArgs>
Action<>
Code:
public static void FillMenuWithPages(this StackPanel spMenu, string menuIdCode,
PagingManager pagingManager, ??????? mouseClickHandler)
{
var menuPageItems = PageItems.GetPageItemsWithMenu(menuIdCode);
spMenu.Children.Clear();
foreach (var pageItem in menuPageItems)
{
var button = new Button();
button.Content = pageItem.Title;
button.Margin = new Thickness { Right = 3 };
button.Tag = pageItem.IdCode;
button.Cursor = Cursors.Hand;
button.Click += new RoutedEventHandler(mouseClickHandler);
if (pageItem.IdCode == pagingManager.CurrentPageItemIdCode)
button.IsEnabled = false;
spMenu.Children.Add(button);
}
}
I would call it like this:
QuickMenu.FillMenuWithPages("quick", PagingManager, Menu_Button_Click);
and this is the mouse click hander:
void Menu_Button_Click(object sender, RoutedEventArgs e)
{
string pageItemIdCode = ((FrameworkElement)sender).Tag.ToString();
PagingManager.SwitchPage(pageItemIdCode);
}