Merge seperate scroll views into one scroll view, from seperate view controllers - c#

I have 3 different views and view controllers. 1 is responsible for displaying some review text, it has a UIScrollView and a UILabel. Another is responsible for displaying comments, it has a UIScrollView a nested UIStackView. The third one, I want to combine the previous 2 and be able to scroll them them together, and it has a UIScrollView (the contained element at this stage can be anything).
I want to keep this separation because the review text will be displayed elsewhere, by itself or with other information as well and I've abstracted the comments so that the same code can be used with a different comment model to display different comments depending on the context; with this particular context being a discussion on the review text.
The end result I'm looking for is that review text and the comments can be scrolled together.
Naively, I've tried adding the view controllers as children and the views to a UIStackView within the UIScrollView and I ended up with two views that scroll independently, more or less. Which makes sense, but is not what I want. I'm finishing testing using UICollectionView and it doesn't seem to work (the child view controllers don't seem to get notified when the view appears, which is where I'm setting the UILabel's text for the review and building the nested UIStackViews for the comments). My next idea is to somehow 'rip' the content out of the views' scroll views and place it into the third's UIScrollView's container (probably a UIStackView). But before I do that, I wanted to see if there was an easier way to effectively merge these 2 scroll views (and their associated view controllers) into a third, containing scroll view (and its view controller).

As per comments from the OP...
You can add the VCs as child view controllers, and then add their views to a UIStackView.
The key to getting that to work is to set the height of the child views (and their scroll views) to match the height of the scroll views' content.
Note that the "root view" of a VC loaded as a child will have .translatesAutoresizingMaskIntoConstraints = true ... so if you're going to use auto-layout constraints, remember to set it to false.

Related

Collection View inside scroll view in xamarin.forms

I am working in xamarin.forms. I have the collection view inside the scroll view. I know it is not a good practice but I am not in a position to change the whole code from scratch. Because of this, there are two scrolls on my single page, especially in IOS. I have gone through several articles, the below link is one of them but I could not access the whole code.
https://luismts.com/collectionview-inside-scrollview/
Is there any workaround? The blue arrows are my two different collection views and the whole page has inside Scroll View.
I suggest you use Bindable layout instead of collectionview here. The bindable layout uses the parent scrollview and this will not create multiple scrollable layouts like collectionview.
Here is the official xamarin documentation: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/bindable-layouts

Wpf MVVM: What exactly needs to be a view?

I'm new to WPF and MVVM and attempting to write a firmware programmer so I can update stuff via USB and save and upload setting/state data. MVVM seems like it could work for this. I currently have pages and can navigate around the app (although the nav service is in code behind for now) but I'm stuck on how to implement things that aren't in the standard 'customer'/'person' examples.
On a couple of pages, there are subsections that I can see being sub-divided into separate views hosted in the page, and these subsections are used more than once in the app.
For instance, I want to have a TextBlock that displays the connection status and updates based on signposts in the connection process, firmware update, backup, etc. Progress bars with the % are another. Sections that are used to display errors, data or a selection box depending on what happens connecting would be another.
Having a sub-section house 3 completely different outputs all stacked on top of one another and shown based on the situation seems messy. I can see that section being a ViewBox and creating a unique view for each case being a better solution there (and possibly the other examples above).
Or take the 'status display', I can see implementing it as it's own view and the page's view model will use a messenger to pass the current status back to the 'status display' view model. I can also see it all just handled by the page's view model via calls to it's own methods. I can also see potentially using a global model to hold the status strings (maybe an enum?) and the view model can be made to pull the correct string into a 'currentStatus' variable.
What is the proper way to approach this? Keep it all a single page? Subdivide the dynamic/changing parts from the static parts?
OP:
Obviously the pages themselves are views, but would it be best to have the 'Status:'display TextBlock and it's value, and the Error/selector section be views also?
If you are asking whether the status and error displays should be UserControls then yes they can be "a view" irrespective of whether the control is using a view model or not.
Incidentally, it is generally better to use DependencyPropertys instead of view models in a UserControl otherwise you will end up having duplicate properties in both the view (so that MainWindow can databind to it) and in your control's view model (purely for the benefit of the user control).
If your UserControl uses DependencyPropertys then both users of the control and your view can both databind to the same set of properties without duplication. In this way you will realise that UserControls have no need for a separate VM.
OP:
...the page's view model will use a messenger to pass the current status back to the 'status display' view model...
Don't do this, this is what data binding is for.

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.

dynamic bottom of Dockpanel as function of chosen Ribbonpage using MVVM

I currently have a Ribboncontrol on top of my main window. On the Ribboncontrol there are several RibbonPages and depending on which RibbonPage is selected I want to display below the RibbonControl a different IDE Layout that suits the need of the chosen RibbonPage.
Is my approach correct that I create different views/viewmodels for each IDE layout and that with each different RibbonPage that is selected a corresponding view/viewmodel is perused? I like to use this approach because then I would not need to communicate between views/viewmodels because the functionality in each RibbonPage is self-contained.
Each view would be a UserControl that encapsulates a DockLayoutManager. I included some screenshots below (SS1 = MainWindow onto which I want to load different views; SS2 = the view that represent a UserControl that in turn represents a DockLayoutManager with all associated LayoutPanels, DocumentPanels, ....)
Question: How would I go about implementing that and is that a workable solution to display different views as a function of the chosen RibbonPage?
It is common to display different view pages that relate to different functions and or tabs of a RibbonControl. Typically you'd have a base view model class that all of your view models extend and a property of that type in your parent view model... let's call it YourViewModelProperty. To change the view, you'd just need to set a new view model to that property:
YourViewModelProperty = new SomeDerivedViewModel()
You can link each UserControl to its related view model in DataTemplates declared in App.xaml. In this way, they'll all be available to every view in the application. You can find out more information regarding this method in my answer to the WPF - automatic view resolving for view model question here on Stack Overflow.
UPDATE >>>
There is a much better explanation available in my answer to the WPF MVVM navigate views question.

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?

Categories