Remember the last settings of expandable/collapsible navigation area - c#

I have a WPF query using the MVVM pattern. The first panel is a navigation area and the second panel is a tab area. Between both is the navigation button. If I click on the navigation button, then it will collapse the navigation area. If I again click this button again, then both the panels are visible.
So all I want to do is have their final state persist through application shutdowns. If the user collapses the navigation area, and closes the application, then next time they open the application, the navigation area should still be closed. I don't want to have to store this information in a DataBase.
How can I achieve this?
The sample look and feel of the image:

If you are using MVVM than you have a ViewModel for that View.
In that ViewModel you should have a command that will be executed when user clicks on Navigation button, so that you can decide what to do with Navigation Area
So basically you could store that info (is Navigation collapsed or not) in Application.Properties.Settings, see http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx
There you create property, e.g. IsNavigationAreaCollapsed of type boolean.
And when command is executed in code do this:
private void OnNavigationButtonExecution()
{
Properties.Settings.Default.IsNavigationAreaCollapsed = !Properties.Settings.Default.IsNavigationAreaCollapsed
CollapseNavigationArea(Properties.Settings.Default.IsNavigationAreaCollapsed); // this will collapse or not the navoigation area
Properties.Settings.Default.Save(); //save settings, so that it will be stored when app shutsdown
}
and in ViewModel constructor add code that will read a value from settings (Properties.Settings.Default.IsNavigationAreaCollapsed) and do this
CollapseNavigationArea(Properties.Settings.Default.IsNavigationAreaCollapsed);

I found one easy way of implementing it.
What I did is created an XML file (outside Bin folder obviously)
passed a default value for grid width to the XML file.
The function which is getting called at the application start I retrieved the value of Grid Width which I set default in XML file(for the first time I am passing a default value) with help of Linq To XML and stored this entry into a variable.
Now,I am passing this variable for Grid length.
Now, if the user collapse/expand the panel and closes the application then simply on Close function I am updating the value of XML.

Related

Binding data for tabcontrol

First of all i'm a newbie on MVVM pattern and C# / XAML developpment. Sorry for the inconveniant.
So the aim is to create a complete application including buttons, tabcontrol and use bindings and commands to gather them all correctly.
Each button represent a specific object which has its own information (name, id, serial number, ...). All these buttons are represented in a specific view which is on a top of the window. At the bottom of this window, i need to show a table with several items and content inside associated to the button pressed.
The problem here is the table. I need to display the information of the clicked object inside the table and the content inside can vary for all tabitems. And one other thing is that when one button in particulary is pressed, the view of the table totally change and display other information.
My questions are :
Do i need to create one model for each of my button / object AND an associated viewModel to it ?
The view including all of the buttons can be a separated view from the table and both of them will be in MainView ?
Can i represent data inside the table like a scrollviewer and is it possible to add new line wih other informations from the model when click on it ?
I hope my explanation is enough to helpor so here is a schematic representation of my application showing different context.
enter image description here
enter image description here
Thanks all of you for your help.
Do i need to create one model for each of my button / object AND an associated viewModel to it ?
You can go both ways. If your model communicates with different API and requires you to use different contract then yes use different models. Otherwise I would suggest using one. About ViewModel it is as well up to you it could be done both ways. I would suggest separation but as of in question I did not find any information about the size of the application itself so it all depends on the size and concern segragation.
The view including all of the buttons can be a separated view from the table and both of them will be in MainView?
You still need root view so everything should in the same view. I could suggest creating a new UserControl for each of the TabWindows then simply just collapse or make it visible depending on button command invoked.
Can i represent data inside the table like a scrollviewer and is it
possible to add new line wih other informations from the model when
click on it ?
You can add ScrollViewer into each of the tabs in TabControl. I am not quite sure what is the question on the second part of it but I would suggest to use ObservableCollection with ItemsSource to dynamically add items to your data table.
More information about MVVM pattern and its applications can be found here.

Implementing a Windows 8 app with nested navigation

I'm currently developing an app for Windows 8 which should provide nested navigation. The main view is split into 3 parts, a menu area on the left side, a Content area and a Header. Both the menu and the Header should be visible all the time.
The Content area is filled with the Content selected from the main menu, however if the user selects for example a list, the Content area is again split into two sections where i want to Show the list on the left side and the selected Detail Information on the right side (similar to the built-in mail app). The Detail view again has subviews, which should be displayed in the same area. I added a back button to navigate through the Detail views.
Each of the views is currently contained in a Frame element, which means i have a MenuFrame and ContentFrame inside the main view, and a ListFrame and a DetailFrame inside the "list"-view. I maintain backstacks for every Frame to enable navigating back.
My question is: if the user wants to snap the application (Display it side by side with other Win8-Apps or the Desktop), the space for the app is very small. Therefore i want to Display only one view at a time in snapped mode, which means the user first sees the main menu, then the list, then the Detail view, and he should be able to navigate back to the parent view in all cases (which means that i would have to maintain a single backstack for all views?).
Is there a simple way to achieve this behavior?
Another question: Currently i don't use the Frame.Navigate-methods, but i implemented my own backstack by just creating UserControls and assigning them to the Frame.Content property. If the app wants to navigate back, the previous control is popped from the stack and set as the Frame Content. The benefit of this is that i can execute code in the control constructor which might raise exceptions. Are there any downside of this method or other reasons why you would recommend switching to the standard Frame.Navigate() pattern?

dynamic window focus MVC2

I am working on an MVC2 project, on a view we display a large data set which refreshes every minute with latest data..some specific records are updated every minute in this data set. I want the browser to focus on these specific records..Not sure how to use javascript focus() here dynamically...
any clue?
thanks,
You need to provide more detail as to exactly what you are attempting to do.
If you are attempting to focus just ensure each record has a unique identifier then you can focus on individual records.
Alternatively you could simply keep the focus at the top or bottom of wherever you are displaying them.
EDIT:
In that case I would suggest something like the following
var currEle = document.getElementById("Record123");
currEle.focus();
Suppose you know how to issue an Ajax call and return either partial view or JSON data and how to use that data on the client afterwards...
You can only focus to a point in the document when
there's only one change or
all changes are summarised together in the same document area
We're also not talking about focusing as in document perspective, but rather about focusing of users attention to document specific content (or part of it).
First option
You can always use something like jQuery.scrollintoview() plugin (link to blog post that describes the plugin here) that will scroll document to the record that changed and highlight it using jQuery UI effect highlight. Linked blog post also describes the purpose of visual animated scrolling instead of simple jumping within the document.
Second option
Put changes at the top and keep your document scrolled at the top when content gets updated. You can blink a few times some icon informing the user of the changed content in the changes area.

What would be the correct way to add multiple views in my app?

I'm working on an app which encodes text to QR codes.
Currently I have a form which does this for a single string.
(source: fotopocket.nl)
At the top I've added a View menu item with two subitems:
Single (which is what we're looking at now)
Bulk (which would allow a user to select an import file)
When the user selects Bulk I want to have a different toolstrip and input fields (but the same menu).
Should I create another form for this with the same dimensions (and menu) and switch the forms when another view is selected.
Or should I code both views in the same form somehow?
Basically I don't want to let the user notice a complete new screen is loaded.
So if I would have to go the 2 forms route I need to make sure the forms will be placed at the same position.
What would be the correct way to get this functionality?
I would suggest creating a UserControl for the content (toolstrip and input fields) for Single and another UserControl for the content (toolstrip and input fields) for Bulk. You could add both to your single form and then show the correct one based on which menu option is selected.
This would give you some of the benefit of having two forms - your event handlers and such would be separated into each UserControl, but you would be loading the content into one user-visible form.

Databound Windows Forms control does not recognize change until losing focus

I use data binding to display values in text boxes in a C# Windows Forms client. When the user clicks Save, I persist my changes to the database. However, the new value in the active editor is ignored (the previous value is saved). If I tab out of the active editor, and then Save, the new value is persisted, as expected.
Is there a way to force the active control to accept its value before persisting?
If you can get the Binding instance that corresponds to the input (the TextBox), you can call the WriteValue method to force the value from the control to the object it is bound to.
Also, you can call the EndCurrentEdit method on the BindingManagerBase class (usually a CurrencyManager class instance) to finish the edit, but that requires implementation of the ICancelAddNew or IEditableObject interface on the object that is bound to (and wouldn't require you to fish for the binding).
The solution I've used is to call ValidateChildren on the Form from the Save event (call), before actually saving the database records. This forces validation of all fields and thus binding to occur without losing focus of the control currently being edited on the form. It is real handy if the save button is on the Windows menu system and not form itself - plus it returns False if data in any control on the form is invalid and thus can be used to prevent saving errant data.
This also gets around inconsistent updating of the bound field that occurs when OnPropertyChanged is used as a binding method instead of OnValidation. Also, it is critical if the binding method is set to Never with separate WriteValue calls made for each validated event trapped per control.
This is kind of a hack, but try setting the focus away from the active editor (by setting the focus to something else, like the save button for example) in the button event before you call save.

Categories