简体   繁体   English

WPF ListView排序丢失最后一行中的列数据

[英]WPF ListView Sorting loses column data in the last row

I am facing a strange behaviour while sorting the WPF ListView ColHeader !! 在对WPF ListView ColHeader进行排序时,我面临一个奇怪的行为! I have a listview binded to a datatable. 我有一个绑定到数据表的列表视图。 Cols have cell templates. 列有单元格模板。

In one of the cell template [salary column], I have multibinding in xaml. 在其中一个单元格模板[salary column]中,我在xaml中具有多重绑定。 When this listview is loaded with data, everything is working fine. 当此列表视图加载数据时,一切工作正常。

And I changed the numeric value of salary columns such as 1,4,3,5,2 in each row respectively. 我分别更改了薪水列的数值,例如每行中的1,4,3,5,2。

ie, in the first row, salary col is 1, second row, salary col is 4, third row salary col is 3, etc. 也就是说,在第一行中,sal col为1,第二行,sal col为4,第三行salcol为3,依此类推。

when i clicked on the salary header column for sorting, the listview is sorting but the last typed value in the salary text box [ie, 2 in here case] disappears !!! 当我单击薪水标题列进行排序时,列表视图正在排序,但是薪水文本框中的最后一个键入的值[即在这种情况下为2]消失了!

ICollectionView myview = CollectionViewSource.GetDefaultView(lv.ItemsSource);

if (myview != null)
{                
   myview.SortDescriptions.Clear();
   SortDescription sd = new SortDescription("Salary", direction);
   myview.SortDescriptions.Add(sd);
   myview.Refresh();
}

When i checked the myview after sort desc is added, the Salary value in the last row disappears !! 当我添加排序desc后检查myview时,最后一行的Salary值消失了! Is there anything wrong in it ??? 有什么问题吗?

I can speculate what is happening based on your description but showing the xaml of the datatable would be useful. 我可以根据您的描述推测正在发生的事情,但是显示数据表的xaml会很有用。 Bindings for the Text property of a TextBox, by default, does not commit the value until it loses focus. 默认情况下,TextBox的Text属性的绑定在失去焦点之前不会提交该值。 Change the UpdateSourceTrigger of your binding to PropertyChanged: 将绑定的UpdateSourceTrigger更改为PropertyChanged:

Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}"

This will commit the value on every key press. 这将在每次按键时提交该值。 Can't be sure if this is your problem without seeing the code. 在没有看到代码的情况下无法确定这是否是您的问题。

Cheers, Eric 干杯,埃里克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM