siverlight datagrid滚动颜色错位问题
来源:互联网 发布:淘宝买家版 编辑:程序博客网 时间:2024/05/01 23:49
如果你记录了行号列号去改变单元格的颜色在滚动的时候就会颜色错位,这是因为在滚动的时候datagrid的列号会变
但是itemsource绑定的集合却不会变,我们可以用哪个集合去取得需要变色的单元格
方法是: var ad = targetDataGrid.Columns[col].GetCellContent(item) as TextBlock;,开始不晓得.GetCellContent还有这个重载
好了现在在datagrid的load_row 事件里加上这个方法就行了
try
{
int listkvsindex = 0;
foreach (var item in listkvs)//row
{
for (int col = 0; col < item.GetType().GetProperties().Count(); col++)
{
var ad = targetDataGrid.Columns[col].GetCellContent(item) as TextBlock;
if (ad != null)
{
KeyValuePair<int, int> m = new KeyValuePair<int, int>(listkvsindex, col);
if (UHService.needtored.Contains(m))
ad.Foreground = new SolidColorBrush(Colors.Red);
else
ad.Foreground = new SolidColorBrush(Colors.Black);
}
}
listkvsindex++;
}
}
catch { }
当然我这个datagrid是动态生成,直接用的原生的会有这个问题,如果后台用动态生成模板就不会有问题了
拼接的方式也是原生的效果,只是不晓得为什么很很卡
internal static DataGridTemplateColumn GetGridViewColumn(string header, string content, string color)
{
DataGridTemplateColumn tempCol = new DataGridTemplateColumn();
tempCol.Header = header;
tempCol.Width = new DataGridLength(80);
StringBuilder cellTemp = new StringBuilder();
cellTemp.Append("<DataTemplate ");
cellTemp.Append(" xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'");
cellTemp.Append(" xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'");
cellTemp.Append(" xmlns:grid='clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView'>");
cellTemp.AppendFormat(" <TextBlock Text=\"{{Binding {0}}}\" Foreground=\"{{Binding {1}}}\"></TextBlock>", content, color);
cellTemp.Append("</DataTemplate>");
tempCol.CellTemplate = (DataTemplate)XamlReader.Load(cellTemp.ToString());
StringBuilder cellTemp2 = new StringBuilder();
cellTemp2.Append("<DataTemplate ");
cellTemp2.Append(" xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'");
cellTemp2.Append(" xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'");
cellTemp2.Append(" xmlns:grid='clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView'>");
cellTemp2.AppendFormat(" <TextBox Text=\"{{Binding {0}, Mode=TwoWay}}\"></TextBox>", content);
cellTemp2.Append("</DataTemplate>");
tempCol.CellEditingTemplate = (DataTemplate)XamlReader.Load(cellTemp2.ToString());
return tempCol;
}
/// <summary>
/// 为datagrid增加一列
/// </summary>
/// <param name="columname"></param>
/// <param name="columnBindName"></param>
public void AddColumn(string columname, string columnBindName,string col)
{
//DataGridTextColumn textColumn = new DataGridTextColumn();//textbox
//textColumn.Header = columname;
//textColumn.HeaderStyle = Application.Current.Resources["MyDaGTextCStyle"] as Style;
//textColumn.CellStyle = Application.Current.Resources["MyCellStyle"] as Style;
//textColumn.Width = new DataGridLength(80);
//textColumn.IsReadOnly = false;//列的格格可以直接输入
//textColumn.Binding = new Binding(columnBindName);
targetDataGrid.Columns.Add(GetGridViewColumn(columname, columnBindName,col));
}
这个问题纠结呀,
- siverlight datagrid滚动颜色错位问题
- Siverlight DataGrid自带滚动条不显示的问题
- siverlight datagrid 导出xml或csv格式,保持颜色一致性
- Siverlight Datagrid样式运用
- Siverlight DataGrid动态表头
- easyui datagrid合并行进入可编辑模式错位问题
- Siverlight 动态生成datagrid复杂表头
- siverlight 原生datagrid 导出excel格式
- 解决ListView、gridview滚动过程中checkbox错位问题
- listview滚动后,内容重复问题,,图片错位
- jquery datatable设置垂直滚动后,表头(th)错位问题
- DataGrid的滚动条不显示问题
- 关于easyui的datagrid detailview的初次点击出现的重叠错位问题
- android ListView多线程解决图片错位问题、缩略图问题、实现顺滑滚动
- SiverLight下BingMap的开发问题
- 关于siverlight程序发布的问题。
- jquery datepicker 在ie7中有滚动条时错位问题
- D3添加title提示信息时出现滚动条时,显示错位的问题
- hdu 1299 Diophantus of Alexandria
- Android 导入多个外部静态链接库, 进行动态库编译方法( NDK)
- 理财专题(6)——保险
- 各协议默认端口
- C# 文件操作
- siverlight datagrid滚动颜色错位问题
- Hadoop 数据类型与文件结构剖析 Sequence, Map, Set, Array, BloomMap Files
- oracle插入时间变量
- 对overflow:hidden的详细理解
- hdu 3802 Ipad,IPhone
- 建造者模式
- Myeclipse/Eclipse 中修改默认字符编码
- 【系统收藏】黑白美女xp主题
- SGU 201 Non Absorbing DFA (DP)