I need to save locally (on a file) a StackLayout object, because I need to save the current state of a page, so I was just wondering if could be possible.
EDIT: Solution
As I have seen, there is no solution!
This is because Views are not serializable, so it's neither possible to serialize the Views as a string (trust me, I have tried them all), the only way is to re-generate your page by saving and loading data of simple types such as int or string (because only simple data can be serialized).
According to your needs, I think you only need to save the user's data and restore it at startup.
You can use File Handling in Xamarin.Forms to save the user's data, and then rewrite the OnAppearing method every time it starts, and restore the data inside the method.
For more information about File Handling, please refer to:https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/files?tabs=macos#saving-and-loading-files
Related
I'm totally new to C#, and got an assignment building a WPF form to modify settings in an existing C# program using Visual Studio and WPF.
I have numerous goals:
Get a list of all of the Settings names.
Retrieve all of the user properties.
Add a line for every setting to the form, and allow the user to restore the original settings, use the current ones, or modify them to a new value.
Make sure that the user input is in the correct Type.
Bind between the TextBox and the values in the line, not sure what is the best way to send the details. What object do you recommend to bind to the xaml? The list containing the property lines? Or to bind every line separately?
I think that I need to access the App.config file for 3, so far unsuccessfully. I would have like to get an advice about the architecture, since I'm new to VS, C# and WPF.
I don't think this is an assignment suitable for someone new to wpf let alone c#.
Even experienced wpf developers are likely to find some tricky bits in this task.
app.config will be in the same folder as your exe. If that is in program files then you will not be able to edit and save. Unless your users are win 7 or earlier.
User settings will usually be stored in appdata for this reason. Since the user is expected to likely want to change them.
They go in a user.config file. The location of one off my system is:
C:\Users\Andrew\AppData\Local\MapEditor\MapEditor.exe_Url_aszfdqs5110y44xmg0kfuuqbatf5la5a\1.0.0.0\user.config
I am user Andrew on the machine and these are the user settings for MapEditor.exe.
The file itself is xml.
In there I see
And there's a bunch of stuff inside that.
I would not try and edit xml directly.
And this is your first bit you'll find isn't exactly easy.
Because you need to translate xml.
"All the user properties."
You presumably know what they are.
Because the user can't just add them.
They need to be defined in the app.
I'd pick out the pieces you want them to change and copy data to a viewmodel. Or observable collection of viewmodels presented by a parent viewmodel.
Probably simplest as an observablecollection.
You can then have a different viewmodel class per type of property.
They enter a string in a number then it'll fail to transfer back to the viewmodel and you can trap validation.errors that'll bubble.
To save, translate the viewmodels back into xml and save it.
I'm just starting to work with windows 8 development (using c#), and am working on porting one of my applications to a windows store app. Essentially my application takes a user input string, calculates an appropriate output, and responds to the user. So I'm using a list view to track the "conversation." I display the user's input as a list view element and then display the output as the next element (using text blocks with formatting like color...).
What I would like to do is make this "conversation" persist once the app is terminated but am not sure the best way to do this. My first thought was to serialize the list view object on suspension then deserialize it on load, but the listview isn't serializable...So my next thought was to write out each input and output string to a file and try to rebuild the listview from these strings when I load the application, but I am having some issues with this as well.
So I'm curious as to what the best way to go about this is. I would like the application to start back up with the previous conversation already displayed with the same formatting and what not. Does anyone have any ideas?
I wouldn't persist the ListView anyway, you only need to persist the data in it. Are you using a MVVM type model, where your conversation is perhaps captured as an ObservableCollection and then bound to the ListView? If not, you should :)
Then you'd just need to serialize the ObservableCollection (see one option for that here). Where you persist it kind of depends on you:
LocalFolder would use a file based approach and be available on the local device
RoamingFolder would also use a file based approach but sync using the cloud across multiple devices that the user owns (and has the app installed)
Cloud storage (like Windows Azure or Windows Azure Mobile Services) would provide essentially boundless storage for you, but requires managing a cloud account and paying for it (though free tiers may be sufficient)
An in-memory database like SQLite is yet another option and would give you relational semantics should that be interesting to you.
To get started, I'd say use LocalFolder and persist your collection to a file, then when you rehydrate it, simple data binding should automatically handle the display. At some point, you may need to make a decision about how much to store. You want your application to be responsive for the user ('fast and fluid'), so to that end you may need to bring in data as it's requested versus all at once (perhaps a version 2 feature!)
I want to write the entire contents of my application page (eg Mainpage.xml) to a file (in Isolated Storage ) How do I do it in WP7 ? are there any methods available to parse the page contents and write it to file in windows phone 7 ?
There is no built in way to do this.
However there are a couple of approaches you could try:
If the structure is static you could try and extract the resource containing this from the DLL. For future re-use it would be easier to load the page from the DLL again though.
If you're generating a page (or part of a page) at runtime (based on user input/preferences) and you want to be able to save/reload this then just save enough information to be able to recreate it. It's unlikely that XAML would be the best format for this though.
You could create this as you build the UI. Alternatively you could walk the visual tree to get details of all that is rendered. I'd recommend recording as you go so you can more easily keep track of non-default values in the rendered objects.
I am creating a site whose content is dynamic and has images in it.
What/How much performance hit will my DB (MSSQL) take if I save content/Images in DB?
I am just trying to understand what kind of problems I may run into.
I appreciate any responses.
Thanks!
If you keep content (e.g. images) outside of the database, you can let IIS serve this content directly without calling ASP.NET at all (and as a consequence, no database access is needed).
You can even put static content on a different server is you have huge load (like here on StackOverflow).
So if you need to scale in any way, keep static content outside of both ASP.NET and database.
In the company where I'm employed we are using a custom-made CMS.
It renders content and controls for a page dynamically. The content are stored in a table for all pages, (each page has one main content), and other tables store information regarding UserControls, path to it, and which properties should be set with which value via reflection.
The performance is good, even for lets say 10 dynamically created controls. Our biggest client's page has about 70k hits a day and there is no performance problem. The page renders really fast.
Storing the images in your database can also work.
Just keep in mind that you need to use server-side caching for your images (e.g. get them via a generic handler *.ashx and use chaching there) and hope that your imageurl gets recognized for clientside caching.
If you want to be sure, expose your images directly on a dedicated image application. (e.g. www.foobar.com is your URL, then you can create images.foobar.com and store all your images there)
If would definetly advise to store often used images there, like images for the layout, or userpictures (if you are using a forum, or some kind of web application that uses several pictures all the time). But there is nothing wrong with storing not often used pictures in the database (user related uploads et cetera).
If you store your images in DB, database size will increase and this will result in slower DB queries. Better store on other media and guide your DB to do the stuff for you.
I've got some controls on a web page that surface configuration elements of my web application.
I've wired up to their "OnChange" events, to capture value changes and so on. For each on change, I would like to say Configuration.Save(), but apart from getting "access denied" exceptions on web.config, I suspect this could be some weirdness, in trying to save to the configuration file for each control's onchange.
Any suggestions for the best way to handle this?
Would you add some detail as to what type of settings you are trying to update? I really don't think you want to save changes to your web.config from the application. Does the application have a database you could tie your saves to? That seems more appropriate for a changes you would want to make regularly, and in a transaction safe manner.
I still think this is better done using a database. But, if you must, then I'd check out this guide to working with web.config.
From an architectural standpoint, it would be better to save the changes to the configuration file when the page is submitted. However, it is likely that the web.config file is locked when the application is started.
Consequently, if you have application-specific changes that you would like to save, it is better to find a method other than web.config for saving them.
You would want to find an alternative to modifying the web.config file directly. Doing so causes your application to restart. Either generate your own XML file or a database configuration set up.