how to set focus at specific position in Entry + xamarin.forms - xamarin

my entry box has some text already.so can I set cursor focus at start of text?
how? I coudnt find any option for that.if anybody have idea.please suggest.

As you said
In mobile app there wont be focus in load of page.as there will not
keyboard open first.. once user clicks on text than keybopard will get
open.so wherever he click focus will be there?
In mobile app On load focus depend on the requirement. Check out most luxurious android app linkedIn login page, have focus in Username Entry without opening keypad. If you want to avoid using custom renderers in XF than you have to do bit compromise with functionality.
Your second point true- Wherever user clicks focus would be there.
Try doing like this, First update Xamarin.Forms version to 3.1.0.697729 from nuget packages & target framework change to Oreo 8.1.
XAML file
<StackLayout>
<Entry x:Name="txtDummy" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
your .cs file
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
txtDummy.Text = "I am focus";
txtDummy.Focus();
base.OnAppearing();
}
}
Look at output screenshot

Related

How to Hide Hamburger Menu icon in Xamarin forms

I need to hide the hamburger menu on certain pages but still hamburger menu icon is visible in some of the pages . I have a tried a possible ways but nothing helped us. And I attached a image for your Reference.
Possible case I tried so far:
In Xaml Page
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="#F8F8F8"
NavigationPage.HasBackButton="False">
</ContentPage>
Xaml.cs (Code Behind)
I put the code in constructor, and this also not helped
NavigationPage.SetHasBackButton(this, false);
And I used ShouldShowToolbarButton in Flyout Page also ,
public static bool showIcon;
public override bool ShouldShowToolbarButton()
{
return showIcon;
}
I tried possible combinations but hamburger icon is still visible only. Most probably am facing this issue in Android
Please give your valuable suggestions.

How to change "Search" button text in keyboard of SearchBar in Xamarin Forms?

I use following code for SearchBar control. When user click on SearchBar, it shows keyboard with "Search" button to search in Keyboard. I want to change name of it.
Here is my current code: Xaml
<SearchBar Text="{Binding SearchText}" Placeholder="Search" />
SS
There is a NuGet package called EntryCustomReturnPlugin. It allows you to change the text on the done button of an Entry.
However I don't think it works with a SearchBar out of the box. You will need to either change your SearchBar into an Entry or write a custom renderer (you can use the source code of the EntryCustomReturnPlugin, the code will be very similar to that).

White/TestStack UI Automation - clicks app button opens a browser, how do I check the url?

I am currently using White/TestStack to test a windows app.
There are scenarios that requires user to click on links to open pages on browser. How do I check the hyperlink is working?
Old question but in case somebody else looking for an answer:
If you check in the White GitHub repository and you browse the UITests and the control tests, you will find the Hyperlink control test. In the sourcecode, you will find several tests according the type of framework used.
The simplest one:
var hyperlink = MainWindow.Get<Hyperlink>("LinkLabel");
hyperlink.Click(10, 10);
Assert.That(hyperlink.HelpText, Is.EqualTo("Hyperlink Clicked"));
The test is based on the used of code-behind for the MainWindow:
private void Hyperlink_OnClick(object sender, RoutedEventArgs e)
{
AutomationProperties.SetHelpText(LinkLabel, "Hyperlink Clicked");
}
XAML code of the hyperlink in the MainWindow
<TextBlock x:Name="LinkLabelContainer">
<Hyperlink x:Name="LinkLabel" Click="Hyperlink_OnClick">Link Text</Hyperlink>
</TextBlock>
So you can used the same method.
TL;DR
You can link the Click() event of your hyperlinks to a method in code behind which update the automation property HelpText of the hyperlink with a specific value for the clicked event.
So in your tests, you will just have to perform the click and then check the automation property value.

Xamarin.Forms - How to disable Tab on TabbedPage?

I'm looking for a way to disable a tab within a TabbedPage. The tab should be still showing up in the TabbedPage header but simply be disabled.
I tried to set the Page to IsEnabled = false but apparently this is not how you do it or I did it wrong. :)
You can create a custom renderer for a tabbed page control and disable user interaction in your platform specific implementation of the renderer.
For example your renderer for iOS would use the UITabBarControllerDelegate Protocol to override
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
and return NO for the tab that should not be selectable. The solution for Android or Windows Phone would work similar.
Here is my self-contained take on #joeriks method, which is a nice quick/simple solution. Annoying that the event args are just EventArgs.
Just add this to your TabbedPage .cs file somewhere.
Page _lastKnownPage;
protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
if (CurrentPage.IsEnabled)
_lastKnownPage = CurrentPage;
else
CurrentPage = _lastKnownPage;
}

Can't Find Specific Listbox for Windows Phone

I am right now looking for a way for a user to open a listbox, choose an option, and the program continues to run, considering the desired option. My best option was to use a listbox I found in the Settings section of the phone.
I don't have a way of explaining this control completely, so I'll use an example. If you go into the Regions & Language section of the phone and then hit Region, you will notice a list pops open. The same listbox is opened when choosing a ringtone. This is exactly what I need for my application. The only problem is, I don't know what it is called. Help!
I included two images
That control is not called a ListBox, Windows Phone calls it the ListPicker. Here's an article explaining how to use it.
The control is included in the Silverlight Toolkit for Windows Phone.
Note that the article is old and a few of the properties for the control have been renamed / made read-only in the latest release of the toolkit.
What you need is the ListPicker from the Windows Phone Toolkit. You'll need to handle changing any settings yourself. This can be done through binding to a property that gets changed or via code that you write.
<toolkit:ListPicker Header="Language" SelectedItem="{Binding SelectedLanguage, Mode=TwoWay}"
FullModeHeader="LANGUAGES" ExpansionMode="FullScreenOnly"
SelectionChanged="ListPicker_SelectionChanged">
<sys:String>English</sys:String>
<sys:String>Spanish</sys:String>
<sys:String>French</sys:String>
</toolkit:ListPicker>
If you need to handle changes:
private void ListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// handle any changes that are needed
}

Resources