I would like to know what is wrong with my data binding. Simply, when I click on an element, I must get the X and Y mouse position. It should reflect on the textboxes. BUt my code does not. Here is the XAML code:
<TextBox Name="positionX_txtbox" Width="58" Text="{Binding x,NotifyOnTargetUpdated=True,UpdateSourceTrigger=PropertyChanged}"/>
<TextBox Name="positionY_txtbox" Width="58" Text="{Binding y,NotifyOnTargetUpdated=True,UpdateSourceTrigger=PropertyChanged}"/>
Here is the class that inherits from INotifyPropertyChanged:
public class VideoViewModel : INotifyPropertyChanged {
private double _x;
private double _y;
public double x {
get { return _x; }
set {
_x = value;
OnPropertyChanged();
}
}
public double y {
get { return _y; }
set {
_y = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler? PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = null) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
This is the code that runs upon mouse click:
VideoViewModel VideoViewModel = new VideoViewModel();
private void Video_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
Point point = e.GetPosition(null);
VideoViewModel.x = point.X;
VideoViewModel.y = point.Y;
DataContext = VideoViewModel;
}
I know this is a beginner level question but I'm fairly new to C# and I'd appreciate any help.