I do not know if there is a better way in WPF, but could use a dictionary with commands, See:
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
//monta o dicionário com os comandos...
cmd.Add("m1", () => { Metodo1(); });
cmd.Add("m2", () => { Metodo2(); });
ChamarMetodo("m1");
ChamarMetodo("m2");
}
static Dictionary<string, Action> cmd = new Dictionary<string, Action>();
static void ChamarMetodo(string cmd_key)
{
if (cmd.ContainsKey(cmd_key))
{
cmd[cmd_key].Invoke();
}
}
static void Metodo1()
{
Console.WriteLine("metodo 1");
}
static void Metodo2()
{
Console.WriteLine("metodo 2");
}
}
It is also possible to use an enumerator to have the commands including facilitating the development:
public class Program
{
static Dictionary<ECmd, Action> cmd = new Dictionary<ECmd, Action>();
public static void Main(string[] args)
{
cmd.Add(ECmd.Metodo1, () => { Metodo1(); });
cmd.Add(ECmd.Metodo2, () => { Metodo2(); });
ChamarMetodo(ECmd.Metodo1);
ChamarMetodo(ECmd.Metodo2);
}
static void ChamarMetodo(ECmd cmd_key)
{
if (cmd.ContainsKey(cmd_key))
{
cmd[cmd_key].Invoke();
}
}
static void Metodo1()
{
Console.WriteLine("metodo 1");
}
static void Metodo2()
{
Console.WriteLine("metodo 2");
}
}
enum ECmd
{
Metodo1,
Metodo2
}