2013-01-15 59 views
0

我有一个listView,其中每个项目由包含Button的dataTemplate组成。这是由于一个要求,点击列表项目就像一个按钮点击,将您移动到“向导”的下一步。WPF - 按钮控制模板...当Command.CanExecute为false时,保持模板项目启用

DataTemplate中的每个按钮都包含一个ControlTemplate。

当该命令的CanExecute为false时,此controlTemplate内部的项目将被禁用。具体来说,在我的下面的示例中,Button的模板(带有图像的那个模板)中的Button也被禁用。

即使与该按钮关联的命令被禁用,如何启用模板中的项目。

摘要:按钮的模板包含另一个按钮。当父按钮的命令被禁用时,模板内的按钮被禁用。

XAML:

<ListView.ItemTemplate> 
    <DataTemplate>     
     <Button Name="nextButton" Height="30" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Wiz:edited}}, Path=DataContext.ACommand}" CommandParameter="{Binding}"> 
       <Button.Template> 
       <ControlTemplate>      
        <StackPanel Orientation="Horizontal"> 
         <Label Content="{Binding}"/> 
         <Button> 
         <Button.Template> 
          <ControlTemplate> 
           <Image Source="{Binding source}"/> 
          </ControlTemplate> 
         </Button.Template> 
         </Button> 
        </StackPanel> 
       </ControlTemplate>      
       </Button.Template> 
      </Button> 
    </DataTemplate> 
</ListView.ItemTemplate> 

回答

0

ButtonBase挂钩命令与它相关联的CanExecute。当CanExecute返回false时,ButtonBase将其缓存并从其IsEnabledCore返回false,从而禁用ButtonBase。当元素被禁用时,其后代被禁用。如果你不希望它被禁用,那么你不应该将它与一个命令相关联(例如,钩住点击)或者不要使用CanExecute将为false的命令(例如,使用不同的包装器命令CanExecute但不调用包装命令的执行),或者不要将其他元素放在按钮中(创建/使用某些在单击listitem时执行命令的附加行为)。

+0

好的建议。谢谢 – tronious