Witam, mam problem z podpięciem Observable Collection do kontrolki ListView stosując bindowanie zgodne z wzorcem MVVM. Program kompiluje się i uruchamia, niestety nie pokazuje zawartości listy. Kod wygląda tak:
MainView.xaml
<Window x:Class="SklepTP.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SklepTP"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:DaneViewModel/>
</Window.DataContext>
<ListView.View>
<Grid> <GridView>
<GridViewColumn DisplayMemberBinding="{Binding IdRachunkuProp}" Header="Id Rachunku" Width="110"/>
<GridViewColumn DisplayMemberBinding="{Binding IdKlientaProp}" Header="Id Klienta" Width="110"/>
<GridViewColumn DisplayMemberBinding="{Binding IdProduktuProp}" Header="Id Produktu" Width="120"/>
<GridViewColumn DisplayMemberBinding="{Binding KwotaProduktuProp}" Header="Kwota" Width="170"/>
</GridView>
</ListView.View>
</ListView>
</Grid></Window>
DataViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace SklepTP
{
public class DaneViewModel : ViewModelBase
{
private Dane dane;
public DaneViewModel()
{
dane = new Dane();
ListaKlientow = new List<Klient>();
ListaRachunkow = new ObservableCollection<Rachunek>();
IWypelniacz wypelnij = new WypelniaczStaly();
wypelnij.WypelnijKolekcjeRachunkow();
ListaRachunkow=wypelnij.RachunkiProp;
}
public List<Klient> ListaKlientow
{
get
{
return dane.ListaKlientowProp;
}
set
{
dane.ListaKlientowProp = value;
this.SetPropertyChanged("ListaKlientow");
}
}
public ObservableCollection<Rachunek> ListaRachunkow
{
get
{
return dane.ListaRachunkowProp;
}
set
{
dane.ListaRachunkowProp = value;
this.SetPropertyChanged("ListaRachunkow");
}
}
public ICommand XML { get { return new RelayCommand(XMLexecute, CanXMLexecute); } }
private bool CanXMLexecute()
{
return true;
}
private void XMLexecute()
{
// IKonwerter serializerXML = new SerializacjaXML();
// dane.ListaKlientowProp = serializerXML.deserializujKlientow("klient.xml");
Klient nowy = new Klient(1, "shd", "dhf", "324554");
Rachunek nowyr = new Rachunek(1, 222, 32, 32);
ListaKlientow.Add(nowy);
ListaRachunkow.Add(nowyr);
}
}
}