I'm troubling to resolve how a textbox should automatically change its value when a object is updated. I have a Temperature class with Name and Value.
public class Temperature
{
public string Name { get; set; }
public double Value { get; set; }
}
In MainWindow.xaml.cs after InitializeComponent(), I create an ObservableCollection _lstTempObs = new ObservableCollection(); and then I add an initial temperature object.
In the main window I have a textbox
<TextBox x:Name="T1" Text="{Binding Path=Value}" HorizontalAlignment="Left" Height="23" Margin="215,55,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
And in MainWindow.xaml.cs I set the datacontext as T1.DataContext = _lstTempObs.LastOrDefault(); The temperature update comes from an API. When I get the mew Temperature object, I add it in the ObservableCollection, but the value isn't change in the GUI.
public partial class MainWindow : Window
{
ObservableCollection<Temperature> _lstTempObs = new ObservableCollection<Temperature>();
public MainWindow()
{
InitializeComponent();
_lstTempObs.Add(new Temperature { Name = "T1", Value = "0.321" });
T1.DataContext = _lstTempObs.LastOrDefault();
}
}