Hello,
I am using MVVM Toolkit in a WPF C# application.
I cannot seem to find a solution to the following problem in relation to databinding and notifying of updates.
In the code below I have a button procedure OnBtnAddSetup, this button will eventually load data from a database and display it in a set of text boxes and labels.
At the moment it manually sets the data within the data members for testing. It updates them however it does not update the fields they are bound to.
In relation to Microsoft MVVM toolkit how should this be done?
I have tried many methods on the internet regarding INotifyPropertyChanged and ObservableObject but have not found any to work as yet.
The binding seems to work two ways except in the case when update from the button command so I think I am sure I am missing some code in the button to notify setupA has been updated.
Thank you for any help whatsoever.
CarSetup Class
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace H.SUT.Models
{
// CarSetup Definition
public class CarSetup // : ObservableObject
{
// CarSetup Type Strings V1 defined for use by the class
public int year { get; set; }
public string championship { get; set; }
// 786 more ..........
}
}
ViewModel
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using H.SUT.Models;
namespace H.SUT.ViewModels
{
public class SetupViewModel : ObservableObject
{
public SetupViewModel()
{
}
private CarSetup setupA = new CarSetup();
public CarSetup SetupA
{
get => setupA;
set => SetProperty(ref setupA, value);
}
private ICommand _btnAddSetup;
public ICommand BtnAddSetupCommand => _btnAddSetup ?? (_btnAddSetup = new RelayCommand(OnBtnAddSetup));
public void OnBtnAddSetup()
{
//Example Data
//INFO
setupA.championship = "F2";
setupA.year = 2022;
// 782 more
}
}
View (just the binding)
<TextBox Text="{Binding SetupA.championship , Mode=TwoWay}" Grid.Column="0" Grid.Row="0" Style="{StaticResource Setup_TextBox}" />
<TextBox Text="{Binding SetupA.year, Mode=TwoWay}" Grid.Column="1" Grid.Row="0" Style="{StaticResource Setup_TextBox}" />