Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何使用MVVM处理ListView的itemtemplate中按钮的启用/禁用?_Wpf_Mvvm - Fatal编程技术网

Wpf 如何使用MVVM处理ListView的itemtemplate中按钮的启用/禁用?

Wpf 如何使用MVVM处理ListView的itemtemplate中按钮的启用/禁用?,wpf,mvvm,Wpf,Mvvm,我有一个ListView控件,它在itemtemplate中有按钮集合,并希望处理ViewModel上每个按钮的启用和禁用。我最好的建议是:使用一个(我通常使用Prism的,或者,你可以通过NuGet下载包,这使它毫无痛苦) 然后将按钮的命令绑定到命令: <Button Command="{Binding MyCommand}" /> 这是由MVVM中的命令绑定处理的。阅读如果有人愿意,他们可以在回答中加以阐述。 <UserControl x:Class="MyControl

我有一个ListView控件,它在itemtemplate中有按钮集合,并希望处理ViewModel上每个按钮的启用和禁用。

我最好的建议是:使用一个(我通常使用Prism的,或者,你可以通过NuGet下载包,这使它毫无痛苦)

然后将按钮的命令绑定到命令:

<Button Command="{Binding MyCommand}" />

这是由MVVM中的命令绑定处理的。阅读如果有人愿意,他们可以在回答中加以阐述。
<UserControl x:Class="MyControl" x:Name="this" ...>

<...>
  <DataTemplate>
    <Grid>
      <Button
        IsEnabled="{Binding DataContext.IsEnabled, ElementName=this}"/>
      <Button
       IsEnabled="{Binding DataContext.IsEnabled, 
 RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MyControl}}}"
    </Grid>
  </DataTemplate>
</...>
</UserControl>