Когда я использую код xaml.
<DataGrid Name="DataGrid1"
ItemsSource="{Binding Path=MainSearchBinding}"
HorizontalScrollBarVisibility="Hidden" SelectionMode="Extended"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="False" CanUserSortColumns="True"
AutoGenerateColumns="False" IsTextSearchEnabled="True" IsReadOnly="True"
RowHeaderWidth="17" SelectionChanged="DataGrid1_SelectionChanged"
MouseDoubleClick="OnDoubleClick" MouseLeftButtonUp="OnMouseClick">
Работает нормально.
При переключении на <WpfToolkit:Datagrid></WpfToolkit:Datagrid>
:
<WpfToolkit:DataGrid Name="DataGrid1"
ItemsSource="{Binding Path=MainSearchBinding}"
HorizontalScrollBarVisibility="Hidden" SelectionMode="Extended"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="False" CanUserSortColumns="True"
AutoGenerateColumns="False" IsTextSearchEnabled="True" IsReadOnly="True"
RowHeaderWidth="17" SelectionChanged="DataGrid1_SelectionChanged"
MouseDoubleClick="OnDoubleClick" MouseLeftButtonUp="OnMouseClick">
У меня ошибка:
"Значение не может быть нулевым. Имя параметра: элемент"
с FindParent<T>(...)
в этой строке:
DependencyObject parentObject = VisualTreeHelper.GetParent(child);
public static T FindParent<T>(this DependencyObject child)
where T : DependencyObject
{
//get parent item
DependencyObject parentObject = VisualTreeHelper.GetParent(child);
//we've reached the end of the tree
if (parentObject == null) return null;
//check if the parent matches the type we're looking for
var parent = parentObject as T;
if (parent != null)
{
return parent;
}
else
{
return FindParent<T>(parentObject);
}
}
Мой код здесь.Открывается новая вкладка, если вы нажимаете на ячейки таблицы данных.
var tabControl = (sender as DataGrid).FindParent<TabControl>();
tabControl.Items.Add(new TabItem() { Header = "Документ", Content = docview, IsSelected = true });
Я знаю, что что-то упустил, пожалуйста, покажите мне, куда двигаться?Заранее спасибо.