Я пытаюсь реализовать SelectionChangedEventHandler для DataGrid из MainViewModel, но продолжаю получать сообщение об ошибке, но если я помещу EventHandler внутри MainWindow, он будет работать нормально.
Error
'HardwareTestView' does not contain a definition for 'DataGrid_SelectionChanged' and no accessible extension method 'DataGrid_SelectionChanged' accepting a first argument of type 'HardwareTestView' could be found (are you missing a using directive or an assembly reference?)
ViewModel
public class MainViewModel
{
private readonly ObservableCollection? _hardwareTests;
public IEnumerable? HardwareTests => _hardwareTests;
...
public MainViewModel()
{
_hardwareTests = new ObservableCollection();
foreach (var item in hardwareTestList)
{
_hardwareTests.Add(new Test(item, string.Empty, string.Empty, "n/a"));
}
}
static void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("TEST");
}
}
View (UserControl)
Подробнее здесь: https://stackoverflow.com/questions/783 ... sercontrol
WPF – доступ к EventHandler в ViewModel из UserControl ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение