【发布时间】:2011-08-16 11:26:27
【问题描述】:
我有一个绑定到视图模型的命令,已启用,但并不总是执行。我该如何调试呢?我使用了 WPF Inspector,它重新确认绑定是正确的。
更多细节: 我有一个选项卡控件,它仅在未选择选项卡时执行关闭选项卡的命令。选择选项卡时,该命令将不会命中。
代码相当标准,我似乎看不到或调试探针。
TabItem 上的模板关闭按钮
<Style x:Key="ClosableStyle" TargetType="telerik:RadTabItem">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentControl Grid.Column="0" Content="{Binding DisplayName}"/>
<telerik:RadButton Grid.Column="1" Margin="3 1 -4 0" Width="16" Height="16" Opacity="0.7" Command="{Binding Path=CloseCommand}">
<TextBlock Text="x" FontFamily="Arial Rounded MT" FontSize="12" Margin="0,-3,0,0" />
</telerik:RadButton>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
命令:
RelayCommand _closePanelCommand;
/// <summary>
/// Returns the command that, when invoked, attempts
/// to remove this workspace from the user interface.
/// </summary>
public virtual ICommand CloseCommand
{
get
{
if (_closePanelCommand == null)
{
_closePanelCommand = new RelayCommand(
() =>
{
this.OnRequestClose();
}
);
}
return _closePanelCommand;
}
}
【问题讨论】:
标签: wpf mvvm command mvvm-light