I`m writing a new control containing three DataGrid's (DG_Top, DG_Center, DG_Bottom).
When trying to set the data for this control nothing happens. The ContextProperties (see below) are filled, but the data is not displayed.
In the UserControl (XGrid) I`ve created some properties to manage the DataBindings:
public static readonly DependencyProperty ItemsSource_TopProperty = DependencyProperty.Register("ItemsSource_Top", typeof(IEnumerable), typeof(XGrid));
public static readonly DependencyProperty ItemsSource_CenterProperty = DependencyProperty.Register("ItemsSource_Center", typeof(IEnumerable), typeof(XGrid));
public static readonly DependencyProperty ItemsSource_BottomProperty = DependencyProperty.Register("ItemsSource_Bottom", typeof(IEnumerable), typeof(XGrid));
public static readonly DependencyProperty DataContext_TopProperty = DependencyProperty.Register("DataContext_Top", typeof(object), typeof(XGrid));
public static readonly DependencyProperty DataContext_CenterProperty = DependencyProperty.Register("DataContext_Center", typeof(object), typeof(XGrid));
public static readonly DependencyProperty DataContext_BottomProperty = DependencyProperty.Register("DataContext_Bottom", typeof(object), typeof(XGrid));
public IEnumerable ItemsSource_Top
{
get { return (IEnumerable)GetValue(ItemsSource_TopProperty); }
set
{
SetValue(ItemsSource_TopProperty, value);
OnPropertyChanged();
}
}
public IEnumerable ItemsSource_Center...
public IEnumerable ItemsSource_Bottom...
public object DataContext_Top
{
get { return (object)GetValue(DataContext_TopProperty); }
set
{
SetValue(DataContext_TopProperty, value);
OnPropertyChanged();
}
}
public object DataContext_Center...
public object DataContext_Bottom...
The binding in the XGrid.xaml is the following:
<UserControl x:Class="WPF.XGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
x:Name="control">
<StackPanel>
<DataGrid ItemsSource="{Binding ItemsSource_Top, ElementName=control}"
DataContext="{Binding DataContext_Top, ElementName=control}"
...
I´m using the XGrid control as follows (in xaml):
<iw:XGrid x:Name="XG_Test" ItemsSource_Center="{Binding}" />
And in the .cs file:
DataTable dt = new DataTable();
dt.Columns.Add("TEST");
dt.Rows.Add(new string[] { "" });
XG_Test.DataContext_Center = dt.DefaultView;
Can anybody tell me why the binding isn't working? THANKS!
-------EDIT 1-------
Visual Studio Output doesn't say anything about an error

DataContext_xproperties? And are you sure the ItemsSource you want to set is in that DataContext? Because in your example, you're settingItemsSource_Centerbut notDataContext_Center, which will default tonulland so your{Binding}will bind to nothing.XG_Test.DataContext_Center = dt.DefaultView;XGridcontrol's DataContext.XG_Test.DataContext = dt.DefaultView;(Shows me the data in the DG_Center) But how can I get the DataGrid to use it's own Context?