-
April 14th, 2014, 04:04 PM
#1
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.
[Serializable]
public class MeterLog : NotificationObject
{
private static MeterLog instance;
public static MeterLog Instance
{
get
{
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)
{
log.Add(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);
file.Close();
}
}
VIEW MODEL
public ObservableCollection<string> ErrorLog
{
get
{
return myHardware.Log;
}
}
My XAML is here
<Window.DataContext>
<vm:ViewModelOne />
</Window.DataContext>
<ListBox Margin="10,10,10,375" x:Name="lvErrors" ItemsSource="{Binding ErrorLog}" HorizontalAlignment="Stretch" Grid.Row="2" />
-
May 13th, 2014, 12:46 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|