另一天,另一个问题。老实说,如果这一切停止的话,那就太无聊了,不是吗?
编辑:似乎所有背景信息都已过时。这是精简版本:
我的 Command 类使用 CommandManagers RequerySuggested 事件来配置 CanExecuteChanged(如下所述:WPF 自定义 ICommand 实现和 CanExecuteChanged 事件)。
public abstract class CommandBase : ICommand
{
public abstract void Execute(object parameter);
public abstract bool CanExecute(object parameter);
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
就我而言,CommandManager 无法建议重新查询,而这可能很重要。现在我必须绕过这个并强制它重新查询。有人知道该怎么做吗?
另一个编辑:我现在已经尝试了很多事情(更改我的命令逻辑,删除控件模板和样式),但仍然陷入困境。不过,我无法在孤立的沙箱场景中重现该问题。我真的认为我在这里遇到了一个错误,因为按钮的行为与其外观不一致,即使样式归结为以下内容:
<Style TargetType="{x:Type Button}" x:Key="CertificateActionButton">
<Setter Property="Background" Value="{DynamicResource CertificateActionButtonBackground}"/>
<Setter Property="BorderThickness" Value="0"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="LightGray"/>
</Trigger>
</Style.Triggers>
</Style>
当我取消焦点然后再次聚焦窗口时,一致性被恢复 - 按钮的外观不活跃,因为它是。
更新:由于我无法重现此问题,因此我关闭了此问题。
它收到的唯一答案是一个很好的答案,但在多次编辑该问题后,q & a 似乎不再相关了。
another day, another problem. Honestly, it would be rather boring if this ever stopped, wouldn't it?
EDIT : Seems all of the background-information is obsolete. Here's the boiled down version:
My Command class rigs up CanExecuteChanged with the CommandManagers RequerySuggested event (as described here : WPF Custom ICommand implementation and the CanExecuteChanged event).
public abstract class CommandBase : ICommand
{
public abstract void Execute(object parameter);
public abstract bool CanExecute(object parameter);
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
In my case, the CommandManager fails to suggest a requery where it would be of some importance. Now I have to bypass this and force it to requery. Does anybody know how to do this?
Another Edit: I've tried really many things now (changing my command logic, removing control template and style), and still get stuck on this. I can't reproduce the problem in an isolated sandbox scenario, though. I really think I am suffering from a bug here, since the Button's behaviour is inconsistent with its looks, even if the Style is boiled down to the following :
<Style TargetType="{x:Type Button}" x:Key="CertificateActionButton">
<Setter Property="Background" Value="{DynamicResource CertificateActionButtonBackground}"/>
<Setter Property="BorderThickness" Value="0"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="LightGray"/>
</Trigger>
</Style.Triggers>
</Style>
When I unfocus and then focus the window again, Coherence is restored - the button the looks as inactive as it is.
Update : Since I haven't been able to reproduce this issue, i close this question.
The only answer it has received was a good one, but after having edited the question so many times, q & a don't really seem related any more.
发布评论
评论(1)
您可以尝试从 CommandManager.InvalidateRequerySuggested() rel="nofollow">这里。
还来自注释:
You could try calling
CommandManager.InvalidateRequerySuggested()
from here.also from the notes: