wpf界面代码
<Grid>
<StackPanel>
<TextBox Text="{Binding Name}"/>
<Button Content="Show" Command="{Binding ShowCommand}"/>
</StackPanel>
</Grid>
wpf业务代码(继承ICommand接口,实例化MyCommand对象ShowCommand)
public class MyCommand : ICommand
{
Action executeAction;
public MyCommand(Action action)
{
executeAction = action;
}
//相应事件
public event EventHandler CanExecuteChanged;
//判断是否执行动作
public bool CanExecute(object parameter)
{
return true;
}
//执行动作
public void Execute(object parameter)
{
executeAction();
}
}
//主页面显示模块