before all, I'm sorry but english is not my native. So, i am developing a wpf application, with thow windows, one present as many button as records on my db and another with a little form to add a new one, but i have one problem. When I add another record to my db OnPropertyChanged does not fire and the new buttons doesn't show up, i think it is because the DataContext.
LugaresWindow.xaml
<ItemsControl ItemsSource="{Binding LugaresBtns}" Margin="0,35,0,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="7" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Button Content="{Binding numero}" Click="openLugar" Tag="{Binding idLugar}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="96" Height="30"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
LugaresWindow.xaml.cs
private void addlugarbtn_Click(object sender, RoutedEventArgs e)
{
//(DataContext as LugarViewService).addLugar("11","6969","A","","1"); **IF I USE IT LIKE THIS IT WORKS!**
EditLugarWindow window = new EditLugarWindow(-1);
window.Show();
}
EditLugarWindow.xaml.cs (confirm the form to add a new record)
if (lvs.addLugar(idparquetxt.Text, numerotxt.Text, sectortxt.Text, matriculatxt.Text, selected))
{
this.Close();
}
And on my LugarViewService.cs
public bool addLugar(string idParque, string numero, string sector, string matricula, string tipo)
{
int newnumero, newtipo, newparque;
try
{
newparque = int.Parse(idParque);
newnumero = int.Parse(numero);
newtipo = int.Parse(tipo);
pmclient.addLugar(newparque, newnumero, sector, matricula, newtipo, 1);
OnPropertyChanged("LugaresBtns");
return true;
}
catch (Exception e)
{
MessageBox.Show("Erro ao adicionar. Por favor verifique o numero de lugar ou o tipo\n" + e.Message);
return false;
}
}
public List<Lugar> LugaresBtns
{
get
{
return pmclient.getLugaresByParque(idParque).ToList();
}
}
So, as you can see, the LugaresWindow.xaml doesnt get updated after i insert a new record using another window. What am I doing wrong?
Thank you all!