I have a grid with a collection of "ItemPresupusto". I need to add a NumericUpDown (by mahApps) to be able to modify the "Cantidad" property of each "ItemPresupuesto" and every time I modify that property, I need to update data in the UI. I've tried everything, but I can not do it. Im use MVVM Light Some help. Thank you!
.XAML
<DataGrid IsReadOnly="True"
SelectionUnit="FullRow"
AutoGenerateColumns="False"
GridLinesVisibility="Horizontal"
ItemsSource="{Binding Articulos}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Cantidad" MinWidth="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<mahApps:NumericUpDown Minimum="1"
IsTabStop="False"
Value="{Binding Cantidad, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
ViewModel
public class PresupuestosViewModel : ViewModelBase
{
public IEnumerable<ItemPresupuesto> Articulos => new ObservableCollection<ItemPresupuesto>(Presupuesto.Items);
}
Class
public class ItemPresupuesto: EntidadBase
{
public decimal Cantidad { get; set; }
}
public class Presupuesto : EntidadBase
{
public virtual List<ItemPresupuesto> Items { get; }
}
The ItemPresupuesto class should implement the INotifyPropertyChanged and interface and raise change notifications for the source property that is bound to the control that you want to refresh whenever the Cantidad or Prico properties are set: