WPF Binding Problem with ObservableCollection
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: WPF Binding Problem with ObservableCollection

  1. #1
    Join Date
    Oct 2013

    Exclamation WPF Binding Problem with ObservableCollection

    I am having a problem binding a log file to a WPF list control.
    My list is ObservableCollection<string>

    My data changes through an even under the hood. My list should change in the window. I do not see changes. As my hardware issues events the data is updating the log file but the view is not updating.

    public class MeterLog : NotificationObject
    private static MeterLog instance;
    public static MeterLog Instance
    if(instance == null)
    instance = new MeterLog();
    return instance;

    private MeterLog()
    Title = "Debug Log\n";
    Add(string.Format("Log Timesttamp:{0}", DateTime.Now.ToShortTimeString()));

    public string Title { get; set; }
    private ObservableCollection<string> log = new ObservableCollection<string>();

    public ObservableCollection<string> Log
    get { return log; }
    private set { log = value; this.RaisePropertyChanged("Log"); }

    public void Add(string msg)

    public void WriteXMLFile()
    MeterLog log = MeterLog.instance;

    System.Xml.Serialization.XmlSerializer writer =
    new System.Xml.Serialization.XmlSerializer(typeof(MeterLog));

    log.Title = "This is the Allication Error Log";

    System.IO.StreamWriter file = new System.IO.StreamWriter(
    AppDomain.CurrentDomain.BaseDirectory +"\\ApplicationLog.xml");

    writer.Serialize(file, log);

    public ObservableCollection<string> ErrorLog
    return myHardware.Log;

    My XAML is here

    <vm:ViewModelOne />

    <ListBox Margin="10,10,10,375" x:Name="lvErrors" ItemsSource="{Binding ErrorLog}" HorizontalAlignment="Stretch" Grid.Row="2" />

  2. #2
    Join Date
    May 2014

    Re: WPF Binding Problem with ObservableCollection

    You need to raise the property changed event for "ErrorLog" whenever the myHardware.Log gets updated.,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!

HTML5 Development Center