-
April 14th, 2014, 04:18 PM
#1
Changing Lists in WPF problem
I am populating a list out of entity framework from a database. However I have to get live data from a piece of hardware and then selectively add the data to the database. I have the itemsource set in my list but when hydrating the collection from a new source if does not update the listview. The data is refreshed on an event from the hardware where I update the RaiseNotifyChanged on the observable list.
can someone help
Here is the code for the View Model
public ObservableCollection<RadGridView.Database.MeterData> MeterDbData
{
get
{
if(bLoadFromDb == true)
{
if (meterDbData == null)
return null;
meterDbData = new ObservableCollection<MeterData>(
trueDbContext.MeterDatas.ToList<MeterData>());
return meterDbData;
}
return meterDbData;
}
set
{
if(bLoadFromDb == true)
{
meterDbData = new ObservableCollection<MeterData>(
trueDbContext.MeterDatas.ToList<MeterData>());
}
else
{
meterDbData = value;
}
this.RaisePropertyChanged("MeterDbData");
}
}
public void MeterHardware_OnFinsihedDownloadMeterUpdateUI(object sender, MeterEventArgs e)
{
bLoadFromDb = false;
MeterDbData = LoadDataFromMeter();
}
private ObservableCollection<RadGridView.Database.MeterData> LoadDataFromMeter()
{
ObservableCollection<RadGridView.Database.MeterData> newlist =
new ObservableCollection<MeterData>();
int count = MeterHardware.ResultsList.Count;
for(int i=0; i < count; i++)
{
newlist.Add(new RadGridView.Database.MeterData()
{
MisTimeStamp = meterHardware.ResultsList[i].TimeStamp,
MisValue = Convert.ToDecimal(meterHardware.ResultLst[i].Value),
});
}
return newlist;
}
Main window XAML
<Window.Resources>
</Window.Resources>
<Window.DataContext>
<vm:TrendViewModel />
</Window.DataContext>
<Controls:MeterResultsListViewUserControl1 HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="lvDatav" Grid.Row="2" Margin="10,129,10,-129"/>
NOW CONTROL XAML
<Control.DataContext>
<vm:TrendViewModel />
</Control.DataContext>
<ListView Margin="10" ItemsSource="{Binding MeterDbData}" >
<ListView.View>
<GridView>
<GridViewColumn Header="TimeStamp" Width="120" DisplayMemberBinding="{Binding MisTimeStamp}" />
<GridViewColumn Header="Result" Width="120" DisplayMemberBinding="{Binding MisValue}" />
</GridView>
</ListView.View>
</ListView>
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
|