After I edit an entity and save it, how do I reload the datasource to refresh the entities? I have a listbox with entities, and after I edit the entities the datasource is still showing the old information. the MyEntityDataSource.Load() method is not working.
The problem arises because I am not navigating to a separate page to do the editing. I am reusing the flipping window from the SLBA template. So when I flip back to the front, i'm basically still using the old object that are still in memory, not creating new objects that will fetch the data again. So I need to renew the old data.
You need to make sure that the ItemsSource property of the ListBox is bound to a collection of objects that implement the INotifyPropertyChanged interface . Ideally the collection itself will implement the INotifyCollectionChanged interface (such as the ObservableCollection generic class).
Related
When saving a new entity something strange happens...
I have a data grid with a list of 'Depots' populated using a domain data source.
When the user wants to add a new 'Depot' this is what happens:
Depot newDepot = new Depot();
newDepot.Name = "My New Depot";
EditDepot popup = new EditDepot(newDepot); // create the popup and pass the newly created Depot
domainDataSource.DataView.Add(newDepot); // add a new Depot to the datagrid
// handle the popup events
popup.CancelClick += (cancelSender, cancelArgs) =>
{
if (GridDataSource.DataView.Contains(newDepot))
domainDataSource.DataView.Remove(newDepot);
domainDataSource.DomainContext.RejectChanges();
};
popup.Show();
The popup constructor then passes the entity to a viewmodel. The viewmodel constructor then creates a new instance of 'ContactInfo', another entity which is linked to 'Depot' (Depot.ContactInfo). After filling in a few properties, the 'Depot' is assigned to a property in the viewmodel and a dataform is used to edit the data. Once the user is happy with the content they will press save. The Depot is added to the context (Context.Depots.Add....) and then the changes are submitted. (It's also worth noting I have tried added the ContactInfo item to the context too, with no joy). The data is saved to the database (via WCF) and everything appears to have worked correctly. The proplem is the datagrid is not displaying the ContactInfo fields, where as it did before the save. As the user edits the data, you can see the datagrid populated behind the popup. If the user refreshes, the data returns. This problem does not happen when the entity is editied.
Now, to throw another spanner in the works... This doesn't happen on all our machines...
We have a build machine and the output does have this problem, however one machine in the building builds a version which does not have this problem! After some investigation, we have found that it appears to be the version of WCF RIA Services. On my machine, I had V1.0 SP1. I Tried V1.0 SP2 and still had the same problem. Now on the machine that works, WCF RIA Services SP1 Beta was installed. After he unistalled this, and installed SP2, the problem occured on his machine.
So, we are relutant to use a beta version in our final release, but unless we can fix this issue we wont have a choice. Does anyone have any ideas? Has anyone seen this issue before?
I have also tried different version of the WCF toolkit with no joy
EDIT: I've created a simple project to show you whats happening
The project retrieves a load of entities and tries to add one. You'll notice the the 'InnerThing' properties dissapear.
Link to project
the issue was that the key property was being set in the insert method in the service.
it looks like this change was not reflected in the client. Changing other properties in the service after submit other than the key did work however.
My question look stupid... but let's ask:
I'm developing a Silverlight website... Data are on the server and I use WCF RIA and Linq to Entities to attack my data.
In My domain service of cource enable Modification on my several tables
I drop on my Silverlight app a Datagrid that fetch data on my table (let's call it tblCustomer for the example)
I've several webcast showing how easy it is to fetch data, update data BUT
I don't know how to INSERT data!!!
My grid is in edit mode.. but I'm not able to add a new row... and if I use the detail view.. it's the same...
Any one could provide help
Regards;
For adding new item you should do it manually: add button within which create and add new Item to collection that you're representing in DataGrid and you'll get new item in grid.
Note: If you're attempting to use MVVM - do same within ViewModel instead code-behind.
My app contains the following moduls:
SystemModel --> SystemViewModel --> SystemWindow
SettingsModel --> SettingsViewModel --> SettingsWindow
My SystemViewModel contain SettingsViewModel and other things.
In my SystemViewModel I create some Instance that its ctor receives SettingsViewModel.
If i want to update the settings I opened new SettingsWindow as ShowDialog with SettingsViewModel as him DataContext. If the user click "ok" I update the settings else I don't update.
My problem is that I dont know how to update the Settings in the Instance that I created in the SystemViewModel (Instance that received SettingsViewModel in his ctor).
Any idea?
Can you create only one instance of settings view model, maybe residing in a common view model that serves kind of a root for the view model and providing the glue that binds the models together?
Something like a view model controller, even if this sound a bit strange. This root view model could react to events from the view models and then can do everything that is required to update the other settings.
Another approach is a messaging based approach like the one that is implemented by MVVM Light Toolit. I have used this once and after the project got rather big this approach was kind of complicated regarding maintenance.
Update:
You can find information about MVVM Light Toolkit here.
I have a Silverlight app that is using the MVVM pattern. I have a WCF service which will allow me to authenticate users (I don't have direct control over that service - assume it is a black box that just returns me the user info and a list of privileges the user has). So, when the app starts up, I want to pull security data from that service.
Right now, when I do this, my views and view models can end up getting initialized before the service returns with the security data. This causes problems because the view models need to disable buttons and make things visible/invisible based on the user having certain privileges.
Is there a pattern that allows me to prevent the initialization of the views / view models until the WCF call has returned? How would you go about solving this problem as elegantly as possible?
Generally, you use BusyIndicator from Silverlight Toolkit for scenarios like this one.
Instead of disabling the UI, it shows them a progress instead.
What you do is provide a IsBusy property on ViewModel. While loading data, set it to True and False rest of the time. Wrap your UI with a BusyIndicator control and bind that property's value with BusyIndicator's IsBusy property.
With this in place, your UI will acknowledge whenever it's busy.
I have an SL3 that makes asynchronous calls to a data service. Basically, there is a treeview that is bound to a collection of objects. The idea is that as a user selects a specific treeviewitem, a call is made to the data service, with a parameter specific to the selected treeviewitem being passed to the corresponding web method in the data service. The data service returns data back to the SL3 client, and the client presents the data to the user.
This works well. The problem is that when users start to navigate through the treeview using the arrow keys on their keyboard, they could press the down arrow key, for example, 10 times, and 10 calls will be made to the data service, and then each of the 10 items will be displayed to the user momentarily, until finishing with the data for the most recently selected treeview item.
So - onto the question. How can I put in some form of delay, to allow someone to navigate quickly through a treeview, then, once then stop at a certain treeviewitem, a call is made to the data service?
Thanks for any suggestions.
Chris
use Rx for silverlight
As suggested by funwithcoding, you could try using the Reactive Extensions for .Net (Rx), I've not used it myself but from what I hear it would do what you're after.
However if you don't feel like you want to / have time to learn Rx etc. maybe look at using a DispatcherTimer to create a slight delay in you Treeview selected event, before you call the service to retrieve the data.