我有一個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>
好的建議。謝謝 – tronious