2013-01-15 41 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