我是WPF的新手,并且学习WPF复合应用程序 我有用户控制,这是一个模块,上面有1个标签和1个按钮 现在我尝试使用看起来像
的按钮上的Command属性<Button Name="button1" Command="{Binding Path = GetCustomerNameCommand}">GetCustomer</Button>
在演示者中我有
public class HelloWorldPresenter : PresenterBase<IHelloWorldView>
{
private readonly IWpfService _wpfService;
public HelloWorldViewModel CustomerViewModel { get; set; }
public ICommand GetCustomerNameCommand { get; set; }
public HelloWorldPresenter(IHelloWorldView view, IWpfService wpfService)
: base(view)
{
_wpfService = wpfService;
GetCustomerNameCommand = new DelegateCommand<string>(GetCustomerName);
View.Presenter = this;
PopulateViewModel(string.Empty);
}
private void GetCustomerName(string obj)
{
throw new NotImplementedException();
}
private void PopulateViewModel(string test)
{
CustomerViewModel = new HelloWorldViewModel { Name = _wpfService.GetCustomer() };
}
}
当我点击Button
时,GetCustomerName()方法没有被执行答案 0 :(得分:0)
我发现了,我正在添加相同的视图2次,这就是造成问题......