I use (WPF) synchronized scroll viewer:
http://www.codeproject.com/KB/WPF/ScrollSynchronization.aspx?msg=3577911#xx3577911xx
The main point, I have two datagrids for which I would like to set synchronized scroll viewers. XAML code:
<DataGrid AutoGenerateColumns="false" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Name="dataGrid1" GridLinesVisibility="None" >
<DataGrid.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="scroll:ScrollSynchronizer.ScrollGroup" Value="Group1" />
</Style>
</DataGrid.Resources>
</DataGrid>
The second one is identical (except the name). Now, the problem is, I populate the datagrid (its cells) with textboxes which have scrollbars as well, and by default they all set the same group. Meaning that for example I have 2000 scrollviewers in the group instead of 2.
So the question is -- how to set a different group for scrollviewers for textboxes? I tried this (it has to be in C# code):
int i = 0;
foreach (var db_col in query.FieldNames)
{
var template = new DataTemplate();
var elemFactory = new FrameworkElementFactory(typeof(TextBox));
// resetting the scrollviewer group ?
elemFactory.SetValue(ScrollSynchronizer.ScrollGroupProperty, "");
template.VisualTree = elemFactory;
var col = new DataGridTemplateColumn();
col.CellTemplate = template;
col.Header = db_col;
grid.Columns.Add(col);
++i;
}
but it does not work. So -- how to set this property for the widget on its own, and not inherit it from the parent?
Remark 1: I changed the original code of synchronized scrollviewer, so now it accepts empty strings as group names.
Remark 2: what is completely odd, when I change the way this property is registered, and set option Inherits to false, it is inherited anyway!