UserControl:
<UserControl x:Class="Project.Views.TestView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Project.ViewModels">
<UserControl.DataContext>
<vm:TestViewModel/>
</UserControl.DataContext>
<Button Command="{binding Path=TestCommand}" Contect="Test"/>
</UserControl>
ViewModel:
namespace Project.ViewModels
{
public class TestViewModel
{
public ICommand TestCommand{ get;set; }
public TestViewModel()
{
TestCommand = new RelayCommand(TestCommand_OnClick) //your Icommand implementation
}
void TestCommand_OnClick(object obj)
{
MessageBox.Show("Clicked the Test button");
}
}
}
Это будет работать. Вы можете добавить пользовательский контроль, в котором вы нуждаетесь.
Просьба поделиться своим кодом, что вы сделали до сих пор. – adminSoftDK