I’m crazy with a very simple Datagrid population via DataContext property (binding a DataTable) in a WPF User Control. I trasnport the code from User Control Project to a WPF Windows Project and it works fine. What happens? Bellow the code that works in WPF Window and dont works in WPF User Control:
XAML:
<DataGrid AutoGenerateColumns="true" ItemsSource="{Binding}" Height="282" HorizontalAlignment="Left" Margin="6,6,0,0" Name="datGrdFalhas" VerticalAlignment="Top" Width="494" FontWeight="Normal" IsReadOnly="True" FontSize="14" TabIndex="211" />
Code:
…
DataTable datTblFalhas = new DataTable();
datTblFalhas.Columns.Add("Alarme",
typeof(string)
);
datTblFalhas.Columns.Add("Momento",
typeof(string)
);
DataRow datRowAlarme = datTblFalhas.NewRow();
datRowAlarme[0] = "a";
datRowAlarme[1] = "b";
datTblFalhas.Rows.Add(datRowAlarme);
datGrdFalhas.DataContext = datTblFalhas;
…
Thanks,
Well friends, after too much tests, I discovered the very, very stupid error: In a method to clean the datagrid (called in tabitem show), I put the command:
and not
cleaning the {Binding} action writed in WPF.
Now works fine. Thanks very much for attention and answers, and sorry for inconvenience.