dev*_*tal 29 wpf datacontext xaml binding
我想将当前的DataContext(它是ViewModel的一个实例)作为WPF Button上的CommandParameter传递.我应该使用什么语法?
<Button
x:Name="btnMain"
Command="infra:ApplicationCommands.MyCommand"
CommandParameter="{Binding ???}"
/>
Run Code Online (Sandbox Code Playgroud)
Arc*_*rus 62
没有路径的空Binding直接绑定到DataContext,所以
{Binding}
Run Code Online (Sandbox Code Playgroud)
足以让它发挥作用!你的例子:
<Button
x:Name="btnMain"
Command="infra:ApplicationCommands.MyCommand"
CommandParameter="{Binding}"
/>
Run Code Online (Sandbox Code Playgroud)
sid*_*ews 12
<Button
x:Name="btnMain"
Command="infra:ApplicationCommands.MyCommand"
CommandParameter="{Binding}"
/>
Run Code Online (Sandbox Code Playgroud)
只要该按钮位于具有DataContext的项目的Visual树中