When I user CellValuePresenter to set one of records's style by vb code(for example:font color=red),It's works ok,but when I scroll the scrollbar (records is large) ,the row i has setted CellValuePresenter will works correctly.
would you give me some code to solved it!
thanks!
Hello,
It should be working correctly as long as you set the style to the records out of view as well. For example, here is an example that simulates alternative background for records with RecordContainerGenerationMode to PreLoad :
<igDP:XamDataGrid DataSource="{Binding}" x:Name="xdg" RecordContainerGenerationMode="PreLoad" Loaded="xdg_Loaded" />
void
xdg_Loaded(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke(
new Action(
() =>
Style st = new Style(typeof(DataRecordPresenter));
st.Setters.Add(
new Setter(DataRecordPresenter.BackgroundProperty, Brushes.LightBlue));
for (int i = 0; i < 100; i++)
if (i % 2 == 0)
var drp = DataRecordPresenter.FromRecord(xdg.Records[i]);
if (drp != null)
drp.Style = st;
}
}) , System.Windows.Threading.
DispatcherPriority.ContextIdle, null);
1. set RecordContainerGenerationMode=PreaLoad
2.click search button and setdatasource to xamdatagrid,then set cell style for some special records
3.record's style was changed that in view,but the record's style will not changed if it's not in the view
This is because of the XamDataGrid's virtualization. When records are scrolled out of and in view, they are recreated and therefore the properties that you have set locally are lost. You can bind the properties that you want to set using (IValueConverter) or turn off the XamDataGrid's Virtualization (RecordContainerGenerationMode=PreaLoad) however, this is recommended if you do not expect to have many records.