how can I change the flow direction of a Xamarin Forms Content Page from Left to Right to Right to Left? something like Windows Phone Flow Direction property?
#Hodor thanks, there is no support for such a thing (at least at this time). a workaround for this when using list views is to create multiple list item templates with LTR/RTL directions and use them accordin g to the current UI culture.
Another workaround for other controls is to implement a renderer for each control type and change its HorizontalOptions or XAlignment according to the UI culture.
it's 2017 and Xamarin forms does not support RTL yet..
It might be worth mentioning that the Grial UI Kit product has just added RTL support.
More details here
Try latest In latest Xamarin forms 3.0.0
If you’re making apps that support right-to-left languages, we have great news for you: Xamarin.Forms 3.0 makes it easier than ever to flip layouts to match language direction!
When supporting languages such as Arabic and Hebrew that flow right-to-left, you may now tap into the very easy to use FlowDirection property on any VisualElement instead of using platform-specifics or effects as you may have used previously. Because you already know the direction the device prefers by accessing Device.FlowDirection, updating your UI could be as easy as adding this to the head of your page in XAML:
FlowDirection="{x:Static Device.FlowDirection}"
For more information about updating your applications to support right-to-left layouts:
Right-To-Left Localization in Xamarin.Forms Blog
You mean the navigation flow?
Usually left => right means adding a page on the navigation stack and right => left means removing it.
You can extend a navigation controller on the "native" C# code and make custom animations. There are many ways to do that. Here's an example in MonoTouch
public partial class ScreenController : UINavigationController
{
private Page currentPage = null;
private void setCurrentPage(Page p)
{
currentPage = p;
//Using present View Controller: will set the current page to root.
PresentViewController(new UINavigationController(currentPage.CreateViewController())
{
ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal,
}, true, null);
//Using custom animation
PushControllerWithTransition(this, currentPage.CreateViewController(), UIViewAnimationOptions.TransitionFlipFromLeft);
}
public static void PushControllerWithTransition(this UINavigationController target, UIViewController controllerToPush,
UIViewAnimationOptions transition)
{
UIView.Transition(target.View, 0.75d, transition, delegate()
{
target.PushViewController(controllerToPush, false);
}, null);
}
}
Related
I am working on a Xamarin project that includes a build for GTK. I am attempting to create a custom renderer for many of the Controls, but am having trouble finding, accessing and changing the properties for the control. For example, I would like to replace the "magnifying glass" icon for the SearchBar control with something more similar to the default icon on the Android platform.
I've created the custom renderer:
namespace MyProject.GTK.CustomRenderers
{
public class CustomSearchBarRenderer : Xamarin.Forms.Platform.GTK.Renderers.SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
var searchBar = Control;
// How do I replace the image?
}
}
}
but from there I am at a loss as there are practically no resources on custom renderers for GTK. I've tried looking at the GTK.Renderers.SearchBarRenderer to see if the class its derived from contains any useful properties or methods, as well as trying to find something meaningful in the GTK documentation and the repository for the Xamarin.Forms.GTK package, to no avail. I'm just not really sure how to understand the inner workings of the controls in this build so I can't figure out what I should even be looking for. Any pointers or resources for this or any GTK specific custom renderer work would be much appreciated.
You can check Xamarin Forms GTK
SearchBar is implmented by the use of element called SearchEntry which uses ImageButton and the icon is set by below code
_searchButton.ImageWidget.Pixbuf = RenderIcon("gtk-find", IconSize.SmallToolbar, null); // Search icon
Refer
SearchEntry.GTK
SearchBar.GTK
This should help you begin modifying, if you can get access to SearchEntry in your custom renderer you can change icon, otherwise you will have to create your own search bar, which takes lot of effort.
Is there a ScrollView event in xamarin that is triggered when the user forces scroll up and scroll is already at top? Many apps uses this as the "command" to update the page.
Currently, there is no PullToRefresh property or RefreshCommand for a ScrollView built into Xamarin.Forms. However, It does exist on ListView as shown in the docs, which you might be able to use instead depending on your needs.
Also, it does look like there is a PullToRefreshLayout opensource project created by James Montemagno you might be able to use to easily implement pull to refresh with a ScrollView, but it has been a while since it's last been updated.
You can use the Scrolled event handler. If the ScrollView is already positioned at the top of the contents and the user "pulls down" then Y amount will be either 0 or negative (I know this will work on Android and iOS, not sure about UWP and others).
scroll.Scrolled += (object sender, ScrolledEventArgs e) =>
{
if (e.ScrollY <= 0)
{
// scrolled when already at top of list
}
};
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
Am new to xamarin technology. I am more of a WPF developer. I wish to develope an application in xamarin that displays data in a table format. Am developing the application in cross platforms which should be running in xamarin.forms, xamarin.Android and xamarin.IOS. The problem am facing is to write a scrollViewer in common for all the platforms. Is there any workaround to write a custom scroll viewer(with both Horizontal and Vertical scrolling) that works in common for the three platforms? It would be helpful if I could be pointed to some blogs or links defining this.
If I understand your question well, your problem is that Xamarin.Forms.ScrollView can scroll only horizontally or vertically.
so you can make a scrollview inside another scroll view one is horizontal and the other is vertical.
Like that
ScrollView scrollView = new ScrollView{
Orientation=ScrollOrientation.Vertical,
Content = new ScrollView{
Orientation=ScrollOrientation.Horizontal,
Content = new StackLayout{
Children={new Label{Text="some text"}}
}
}
};
It seems, as you are searching for a Grid...?
Maybe you should have a look and the component store:
free Grid-control from DevExpress
Note: There also are some other Grid-components in the store (but not for free:-)
First, SelectedIndex is not exposed in markup, so you have to do it in code behind, right?
Second, I have set the binding in code behind:
Binding binding = new Binding("Main.PanoSelectedIndex.ObservedObject");
binding.Mode = BindingMode.TwoWay;
rootPano.SetBinding(Panorama.SelectedIndexProperty, binding);`
(ObservedObject implements iNotifyChanged)
The binding path points to my Main view model, and I can see that the PanoramaItem is updating the binding. However,the panorama does not respond when something else (a MVVM Light command) changes the binding. Any ideas?
Thanks,
Roger
To quote from the Windows Phone Developer FAQ
Panorama is designed so the user is in control, there fore you cannot set SelectedIndex programmatically, or force a navigation to a panorama item.
You can set the DefaultItem so that when your panorama is first launched, the panorama navigates to that item, but you can’t navigate programmatically beyond that. DefaultItem can also be used so that a back navigation feels like the item where the user was at did not change.
UPDATE: You can use the DefaultItem to save/restore the selection for a Panorama as shown below (code from Jeff Prosise's recent blog post):
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
// Save the Panorama control's SelectedIndex in page state
State["Index"] = PanoramaControl.SelectedIndex;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Restore the Panorama control's SelectedIndex
if (State.ContainsKey("Index"))
PanoramaControl.DefaultItem = PanoramaControl.Items[(int)State["Index"]];
}
As far as I know SelectedIndex is a readonly property in Panorama ( Weired why WP7 SDK made it readonly). So you will get only UI change back to your VM, and you cant update UI through the VM propertychange.
And DefaultItem is the property which used to set the index programatically.
Again the issue of programatically setting an already instantiated Panorama is that, the alignment of the Title and Panoramaitem wont be in sync. Anyway I am not discouraging but there is still some chance of hack there.