WPF Datagrid分组-具有绑定转换器的项目不会动态更新
||
这是WPF的新功能,它使用datagrid控件对项目进行分组,数据来自Java消息Q,并且在到达项目时对其进行动态添加。
我正在使用GroupStyle来显示分组名称,项目计数,并且读取的自定义转换器将显示已执行的数量。
我遇到的问题是,项目计数随着项目到达的时间而更新,但是未调用自定义转换器类。
<DataGrid.GroupStyle>
...
<TextBlock.Text>
<MultiBinding StringFormat=\"{}{0}, Count: {1:#0}, Executed Qty: {2}\">
<Binding Path=\"Name\" />
<Binding Path=\"ItemCount\" />
<Binding Path=\"Items\" Converter=\"{StaticResource convertToExecutedQty}\" />
</MultiBinding>
</TextBlock.Text>
.....
</DataGrid.GroupStyle>
在Converter类中:
public class ConvertToExecutedQty : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value is IEnumerable<Object>)
{
IEnumerable<TickOrderViewModel> orders = ((IEnumerable<object>) value).GetBaseElements<TickOrderViewModel>();
if (orders.Count() > 0)
{
var BuyQty = ( from n
in orders
where n.side.ToUpperInvariant() == \"BUY\"
select n.executed_qty ).Sum();
var SellQty = ( from n
in orders
where n.side.ToUpperInvariant() == \"SELL\"
select n.executed_qty ).Sum();
return BuyQty - SellQty;
}
}
return null;
}
在上面的转换器中,当选项卡加载时,当有2个项目从MQ读取时一个接一个地加载时,“ orders”计数为1。
例如:我有2行,卖出为1,卖出为1
最初加载时,集合仅看到1行,执行的数量显示-3。
当我切换选项卡时,订单现在有2个项目,并且Exe数量变为正确值-2
有什么想法吗?
没有找到相关结果
已邀请:
1 个回复
镶骄册筷