Rav*_*i V 1 c# wpf desktop-application mvvm
我想在用户控件内实现网格左键单击。
我的 WPF 用户控件
<Grid>
<Border Grid.Row="0" CornerRadius="7" >
<Border.Background>
<SolidColorBrush Color="#ffffff" Opacity="0.08"></SolidColorBrush>
</Border.Background>
<Grid>
<Image Source="/Assets/Images/Icon/ic-add.png" Width="70" Height="70"/>
</Grid>
</Border>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这是我的窗口
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<usercontrols:CreateNewProfile Width="200" Height="235" Margin="40,40,0,0">
</usercontrols:CreateNewProfile>
</<StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
有一个名为 CreateNewProfile 的命令
非常直接的问题如何在用户控件的左键单击上绑定命令?
您可以在 UserControl 内部使用 InputBindings:
<Grid.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding CreateNewProfile}"/>
</Grid.InputBindings>
Run Code Online (Sandbox Code Playgroud)