首先,这是我的第一篇文章上的SO,所以要温柔;)RelayCommand不触发在某些电脑上
我有一个非常简单的WPF应用程序与两个选项的菜单,并在不同意见的一些按钮,大多数这些数据绑定到Microsoft.TeamFoundation.MVVM.RelayCommand。当我的电脑上调试这一切工作正常,运行内置exe文件时,它工作得很好,我的同事电脑内置版本工作正常,但在我的办公室没有另一台计算机上进行测试时,这些RelayCommands的将火...
上XAML:
//Menu item
<MenuItem Header="Quit" Command="{Binding QuitCommand}" />
//Button
<Button Content="Update" Command="{Binding UpdateCommand}"
IsEnabled="{Binding Ready}" Height="30" />
C#:
//Menu item
public ICommand QuitCommand
{
get
{
return new RelayCommand(() => Quit());
}
}
//Button
public ICommand UpdateCommand
{
get
{
return new RelayCommand(() => Update());
}
}
有关计算机方面的信息:
My computer: Win8 Pro 64, .NET 4.5
My colleagues computer: Win7 Pro 64, .NET 4.5
Office computer: Win7 Pro 32, .NET 4.5
该溶液是专为目标框架4.5和处理器体系结构86。其他数据绑定,如上面的IsEnabled和各种文本属性,似乎工作正常。
请告诉我,如果我可以提供任何其他信息!
更新:我做我自己的实现RelayCommand的工作正常:
public class RelayCommand : ICommand
{
readonly Action<object> mExecute;
readonly Predicate<object> mCanExecute;
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
mExecute = execute;
mCanExecute = canExecute;
}
public RelayCommand(Action<object> execute)
{
if (execute == null)
throw new ArgumentNullException("execute");
mExecute = execute;
mCanExecute = delegate { return true; };
}
public RelayCommand(Action execute)
{
if (execute == null)
throw new ArgumentNullException("execute");
mExecute = new Action<object>(param => execute());
mCanExecute = delegate { return true; };
}
public bool CanExecute(object parameter)
{
return mCanExecute == null ? true : mCanExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
mExecute(parameter);
}
}
我不知道我的执行情况和TeamFoundation一之间的区别是什么。
您正在回答其他问题... – Ucodia
你怎么知道这是每次都返回一个新实例 - 是不是问题?和顺便说一句我的解决方案适用于我的项目的每台maschine – blindmeis
我试过了,它没有任何区别。 – moggizx