2010-11-29 63 views
6

我已绑定到ICommand按钮看起来停用,直到我点击的东西

<Button Content="Remove" Command="{Binding RemoveCommand}" x:Name="btnRemove" Visibility="Collapsed" /> 

后一些任务按钮完成后,我做了按钮可见,但他们停用,直到我点击的东西,为什么就是它?该RemoveCommand看起来像下面

public ICommand RemoveCommand 
{ 
    get 
    { 
     if (_removeCommand == null) 
     { 
      _removeCommand = new RelayCommand(() => 
      { 
       if (RemoveRequested != null) 
        RemoveRequested(this, EventArgs.Empty); 
      },() => 
      { 
       // CanExecute Callback 
       if (Status == WorkStatus.Processing || Status == WorkStatus.Pending) 
       { 
        Debug.WriteLine("Returning False" + Status); return false; 
       } 
       Debug.WriteLine("Returning True"); return true; // After uploads, this returns True, in my Output Window. 
      }); 
     } 
     return _removeCommand; 
    } 
上传后

,该CanExecute回调返回True,所以按钮应该被启用,但是直到我点击的东西,它看起来禁用,为什么会出现这种情况?

Video of the Problem

回答

0

如果CommandManager.InvalidateRequerySuggested()没有做的工作,尝试强制含在此时,相应时间的按钮控制焦点(的MouseEnter,加载中...):

//void ParentControl_MouseEnter(object sender, MouseEventArgs e) 
void ParentControl_Loaded(object sender, RoutedEventArgs e) 
{ 
    this.Focusable = true; 
    this.Focus(); 
} 

它可能不是最完美的解决方案但为我工作。