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