Converter lagging behind updates
Posted: 19 Oct 2022, 22:13
Hello!
I am filtering through an observable collection and counting element with a specific property and returning a string of that value. Upon using this converter, the value seems lag behind an update. For instance, if I increase the count, it shows the previous count. However, the initial count on load seems to be correct. On the other hand, not using the converter seems to update correctly.
Is there a chance that I may be missing something to force the value to update with the converter?
I am filtering through an observable collection and counting element with a specific property and returning a string of that value. Upon using this converter, the value seems lag behind an update. For instance, if I increase the count, it shows the previous count. However, the initial count on load seems to be correct. On the other hand, not using the converter seems to update correctly.
Is there a chance that I may be missing something to force the value to update with the converter?
Code: Select all
ListCountConverter::TryConvert(
Noesis::BaseComponent* itemsSource,
const Noesis::Type* /* targetType */,
Noesis::BaseComponent* parameter,
Noesis::Ptr<Noesis::BaseComponent>& result)
{
int itemCount = 0;
Noesis::IList* items = Noesis::DynamicCast<Noesis::IList*>(itemsSource);
Noesis::ObservableCollection<CustomStruct>* structs =
Noesis::DynamicCast<Noesis::ObservableCollection<CustomStruct>*>(
items);
if (items && Noesis::Boxing::CanUnbox<Noesis::String>(parameter))
{
const char* filterString = Noesis::Boxing::Unbox<Noesis::String>(parameter).Str();
int numItems = structs->Count();
for (int i = 0; i < numItems; ++i)
{
CustomStruct* structItem = structs->Get(i);
if (structItem->GetSubscription() == filterString)
{
itemCount++;
}
}
}
else
{
return false;
}
std::string returnValue = itemCount > 0 ? "(" + std::to_string(itemCount) + ")" : "";
result.Reset(Noesis::Boxing::Box(returnValue.c_str()));
return true;
}
Code: Select all
<TextBlock
VerticalAlignment="Center"
Foreground="{DynamicResource ColorBrush.white}"
Text="{Binding Path=itemList, Converter={StaticResource ListCountConverter}, ConverterParameter=test, UpdateSourceTrigger=PropertyChanged}" />