前端:
<Window x:Class="Demo.ObjDataProviderDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ObjDataProviderDemo" Height="300" Width="300">
<Grid>
<Button Content="OK" Click="Button_Click"/>
</Grid>
</Window>
后台:
namespace Demo
{
public partial class ObjDataProviderDemo : Window
{
public ObjDataProviderDemo()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ObjectDataProvider odp = new ObjectDataProvider();
odp.ObjectInstance = new Calculator();
odp.MethodName = "Minus";
odp.MethodParameters.Add(200);
odp.MethodParameters.Add(130);
MessageBox.Show(odp.Data.ToString());
}
}
class Calculator
{
public int Minus(int from, int to)
{
return from - to;
}
}
}