Xamarin.Forms MasterDetailPage with part of master visible on detail - xamarin

I want to push (make visible) little part of master page to detail page like on pictures in links below. Is it possible in Xamarin.Forms?
Before swipe
After swipe
I'll be grateful for help.

Set
<ContentPage NavigationPage.HasNavigationBar="False">
Place a StackLayout or Grid that looks like the side menu shown in your image. Add a tap gesture recognizer to it.
slMenu.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() => ShowSideMenu(masterPage)),
});
private void ShowSideMenu(MasterDetailPage masterPage)
{
masterPage.IsPresented = !masterPage.IsPresented;
}

This is possible, but requires quite some work, since you can't access the width of the MasterDetailView directly.
In another post (see How to set width for MasterDetailPage in xamarin forms ) I have described how to change the width of the MasterDetail view.
While implementing that, I came across a behaviour like you want to have, though for me it was an error.
Basically the steps would be
Implement a custom version of the MasterDetail view where you can set up a custom width
Change the width of the master view so it is a bit wider than it should be
Adapt the calculations when collapsing and expanding the view so that they don't collapse the entire width
For instance if your Master View gets a width of 340 and you want the last 40 to show, make sure that when being collapsed it "only" moves by 300

Related

How to make a drag and drop in Grid Layout in Xamarin forms?

What I want to achieve is to drag red box view and drop in on the aqua boxview. The aqua box view should then take the place of the redbox view. How can I achieve this in Xamarin Forms ? I have added the following XAML code below. Please someone help me with this.
AFAIK Xamarin.Forms does not support drag-n-drop out of the box, hence you'll have to implement it yourself. It won't be easy, since there are certainly some edge cases to consider, but it's achievable. Basically the steps could be (maybe there are other options)
Add an AbsoluteLayout that wraps your Grid
Add an PanGestureRecognizer
When the pan gesture starts, check if it's on the red BoxView
If so, move the red BoxView to the AbsoluteLayout and remove it from the Grid
Move the red BoxView if the pan is updated
When the users stops the pan, check whether the red BoxView where you'd expect it to be dropped
If so, drop it (whatever that means in the context of your app)
If not, animate it back to its original position, remove it from the AbsoluteLayout and add it to the Grid
If you have tried to implement it and are stuck with a more concrete issue, feel free to ask another question about it.

Xamarin Forms: Hide a Stack While Scrolling a list

I have a Xamarin forms Page which is divided into 2 sections, the top 40% contains the Search controls inside a stack layout, the other 60% contains a list view. While scrolling the list view up I want to hide the Stack Layout at the top covering 40% of the screen.
I achieved to implement scroll events of the list from below reference:
https://github.com/velocitysystems/xf-controls/blob/master/XF.Controls/XF.Controls/Views/ListView.cs
I am able to hide the stackLayout but there is a lot of flickering. Any idea how can I stop the flickering? the output is not crisp and stable.
You can use animation TranslateTo for StackLayout.
Example:
OnScrolled()
{
Device.BeginInvokeOnMainThread(() => {
if (isScrollToUp)
HeaderStackLayout.TranslateTo(0,-500);
else
HeaderStackLayout.TranslateTo(0,500);
});
}
You could put the search controls as the header of the ListView:
https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/customizing-list-appearance/#Headers_and_Footers
As the header is a part of the ListView itself it will scroll as expected once you have enough content to scroll through.

How can I make the top and bottom elements of my view controller stay in place, while the middle has elements to vertically scroll through?

I'm working in Swift 3 and XCode 8.
I tried to find the answer to this question, but maybe I don't know how to ask it properly. I'm trying to have a title bar at the top of a view controller and have a back and next button at the bottom of the view. The content in between is longer than the space that exists, so I would like the user to be able to scroll the middle, but keep the top and bottom elements anchored in place.
I've tried to use a container with another view controller that is larger than the container to make this happen, but it just resizes the child view controller.
If I'm not explaining something properly, please let me know and I will try to give more information about what I've missed.
I'm making a few assumptions about your Views:
Navigation Bar for your title
Toolbar to hold your Back and Next buttons
Try the following:
Place a Navigation Bar as seen below. Do not set any constraints.
Place a Toolbar as seen below. Again, do not set any constraints.
Place a Scroll View in the centre of your View Controller and expand it so that the top and bottom are aligned with the navigation bar and toolbar respectively. Again, do not set any constraints.
Highlight all of the Views in the View Controller and place them in a Stack View.
Pin the Stack View to the Superview. These are the only constraints that are set in the example below.

Xamarin set content view width to root view

I'm using Xamarin Auto Layouts with Storyboard on Visual Studio 2015.
I have a root view, Scroll View and Content View.
I want the application to only scroll on the y-axis but scale on the x-axis.
I want to do something like this.
Adding a view to a scroll view that will stretch to fill available width
Which is setting the width of the content view to the root view.
But using Xamarin this does not seem possible.
So in this example, if I run the application, I have to scroll to the right to see the right most label. I want all three labels to show up on the iPhone, by scaling down on the x-axis.
I have also tried using the "I" handle on the content view in storyboard UI Designer of Xamarin VS, but it doesn't identify the root view.
If it's not possible using storyboard, I will settle with code.
I have tried this.
public override void ViewDidLoad()
{
ContentView.Frame = new CoreGraphics.CGRect(ContentView.Frame.X, ContentView.Frame.Y, View.Frame.Width, ContentView.Frame.Height);
//ScrollView.TranslatesAutoresizingMaskIntoConstraints = false;
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
But it doesn't do anything to help me.
How can I scale the UI down on the X-axis while on top of a scroll view using Xamarin.ios?

Receive touch events after settings StackLayout.TranslateX property

I have a ContentView with a StackLayout with multiple children sized to the full width of the screen. In other words, if the screen width is 320 and I have five children, the inner StackLayout is resized to 1600.
In this ContentView, I have Next and Previous buttons that when clicked, animate the inner StackLayout's TranslateX property. Basically, I'm creating a carousel by translating the StackLayout within the ContentView. I chose this route because I was having layout issues using a ScrollView and a custom renderer when I would modify that layout of the view (by hiding labels, etc.)
However, I've hit a snag. Content that appears after I set the TranslateX property doesn't receive any tap events. I believe I might have to reset some tappable area, but I'm not even sure where to begin with that. Does anyone have any suggestions?
I posted this same question in Xamarin's Forums, and someone there answered. For anyone looking, the answer is here: https://forums.xamarin.com/discussion/comment/142914/#Comment_142914
If that link stops working at some point in the future for some reason, the relevant answer is:
Hit testing is done based on the actual frame of the control determined by layout, but translation happens after layout. Therefore hit testing does not take translation into account. If you want a view to be touchable then you should update its layout directly rather than using translation.

Resources