I have a DataGrid, follow the XAML :
<DataGrid ItemsSource="{Binding Path=propCollection}"
SelectedItem="{Binding Path=SelectProp, Mode=TwoWay}"
Margin="-1,159,0,0"
RowDetailsVisibilityMode="Visible"
AreRowDetailsFrozen="False"
CanUserReorderColumns="False"
CanUserSortColumns="True"
CanUserResizeRows="False"
SelectionUnit="FullRow"
AlternatingRowBackground="{x:Null}"
SelectionChanged="dgProprietarios_SelectionChanged"
AlternationCount="0"
Height="200"
HorizontalAlignment="Left"
Name="dgProprietarios"
VerticalAlignment="Top"
Width="645"
AutoGenerateColumns="False">
<...Columns...>
</DataGrid>
On my Window_Loaded I do the following :
dgProprietarios.DataContext = new ProprietariosViewModel(new Dictionary<string, string>());
My ProprietariosViewModel is the following :
public CollectionProprietarios propCollection { get; set; }
public ProprietariosViewModel(Dictionary<string, string> Where)
{
propCollection = new CollectionProprietarios(Where);
}
The CollectionProprietarios class inherits ObservableCollection and have the following code :
public CollectionProprietarios(Dictionary<string, string> Where)
{
Add(new Dados(Where));
}
public new void Add(Dados dados)
{
base.Add(dados);
}
The class Dados have the following code :
public DataTable ProprietariosRetorno { get; private set; }
public Dados(Dictionary<string, string> Where)
{
var ado = new ADO();
ProprietariosRetorno = ado.RetornaSelect(MontaQuery(Where));
}
The function MontaQuery just creates a string that contains a SELECT clause and RetornaSelect executes this Query.
The class ADO, when instanciated just creates the database and the table if it doesn’t exist.
The problem is, all of that is working. While debugging, I can retrieve the value inside the DataContext and it contains the DataTable with values. But for some reason, it doesn’t appear on the DataGrid when the program is running.
So the question is, what am I doing wrong ?
Try to use