How to update the converted value with IValueConverter without property change

Emon Haque 3,176 Reputation points
2021-05-19T19:34:25.493+00:00

The problem is in Edit Transaction view. For the proper update of transactions, ListBox, I've added an additional string property, TenantName, in the Transaction model and when I update the Tenant's name, I fire an event NameChanged in the EditTenant viewmodel and Transaction view model is a subscriber of that event and does this to update the TenantName:

EditTenantVM.NameChanged += onTenantNameChanged;  
void onTenantNameChanged(Tenant t) {  
    if (transactions == null || transactions.Count == 0) return;  
    foreach (var item in transactions) {  
        if(item.TenantId == t.Id) {  
            item.TenantName = t.Name;  
            item.OnPropertyChanged(nameof(Transaction.TenantName));  
        }  
    }  
}  

it works fine. Now, I've another event in EditPlot viewmodel and it's fired when plot's Name changes. Transaction view model is a subscriber to that as well BUT Transaction model doesn't have any string PlotName property, it's int? PlotId property and that is set in the group description:

Editables.GroupDescriptions.Add(new PropertyGroupDescription(nameof(Transaction.PlotId)));  

in the ControlTemplate, I've used converter to convert the PlotId to Name:

plotName.SetBinding(Run.TextProperty, new Binding(nameof(GroupItem.Name)) {   
    Mode = BindingMode.OneWay,   
    Converter = App.convert.plotId2plotName   
});  

in the handler or Plot's NameChanged I've tried with these in Transaction view model:

EditPlotVM.NameChanged += onPlotNameChanged;  
void onPlotNameChanged(Plot p) {  
    if (transactions == null || transactions.Count == 0) return;  
    foreach (var item in transactions) {  
        if (item.PlotId == p.Id) {  
            item.PlotId = p.Id; // PlotId actually didn't change, only the Name changed  
            //item.OnPropertyChanged(string.Empty);  
            item.OnPropertyChanged(nameof(Transaction.PlotId));  
        }  
    }  
}  

BUT it doesn't update the Name in Transaction view!

97957-test.gif

Is it possible, somehow, to force it to call the IValueConverter, App.convert.plotId2plotName , to get the updated value?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,632 questions
{count} votes