在我的主页中,我有一个所有项目的列表视图,一旦用户单击其中一个,它将导航到详细信息页面。在详细信息页面中,我创建了一个最后一个按钮来跳转到最后一个项目,
<Button Content="Last" HorizontalAlignment="Center" >
<Interactivity:Interaction.Behaviors>
<Interactions:EventTriggerBehavior EventName="Click">
<Interactions:InvokeCommandAction Command="{x:Bind Path=ViewModel.LastCommand, Mode=OneWay}"/>
</Interactions:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</Button>
这是我的页面视图模型的一部分
class DetailPageViewModel : ViewModelBase
{
private MyItem item;
public MyItem Item
{
get { return item; }
set { SetProperty(ref item, value); }
}
public DetailPageViewModel()
{
LastCommand = new DelegateCommand(LastItemExecute, CanLastItemExecute);
LastCommand.ObservesProperty(() => Item);
}
private DelegateCommand lastCommand;
public DelegateCommand LastCommand
{
get { return lastCommand; }
set { SetProperty(ref lastCommand, value); }
}
private bool CanLastItemExecute()
{
if (Item.Index!= 1)
{
return true;
}
else
{
return false;
}
}
private void LastItemExecute()
{
Item= _context.Items.Single(p => p.Index== Item.Index- 1);
}
}
这里一切正常,除了如果我单击列表视图中的第一项,或从第二项跳转,最后一个按钮将不会被禁用,但单击它不会做任何事情。但是,如果详细信息页面显示第一项,我想禁用该按钮,请问有什么帮助吗?