Recently I have switched to Xamarin.Forms 2.4.0.18342 and now on iOS (10 and 11) the default white background for Entry controls is lost if the control was hidden and then shown.
A simple layout:
<StackLayout Orientation="Vertical" Padding="50">
<Button Text="Hide" Clicked="OnHideClicked"/>
<Button Text="Show" Clicked="OnShowClicked"/>
<Entry x:Name="PasswordEntry" Placeholder="Password" HeightRequest="44" AutomationId="PasswordStyleId" IsVisible="true"/>
</StackLayout>
looks like this:
But if I tap the Hide and then Show buttons with the following code behind:
void OnHideClicked(object sender, System.EventArgs e)
{
PasswordEntry.IsVisible = false;
}
void OnShowClicked(object sender, System.EventArgs e)
{
PasswordEntry.IsVisible = true;
}
the white background is no longer there:
Update 1
It works fine on Xamarin.Forms 2.3.4.270, but breaks on 2.4.0.280.
Update 2
Xamarin Bug: 60261
Related
I have a button added using <Button Text="Next" Clicked="Button_Clicked"></Button> How can I make my button display different text each time it is clicked?
You need to give a name to your Button in order to get hold of it in your Button_Clicked method.
<Button x:Name="MyButton" Text="Next" Clicked="Button_Clicked" />
Then in your code behind:
private void Button_Clicked(object sender, EventArgs args)
{
MyButton.Text = "Hello, World!";
}
I have some problem with Xamarin forms on Completed event which has been triggered when the control have focus (Entry)
Below is the View :
<Entry
x:Name="EntryOrderNumber"
Placeholder="MFGO Number"
Text="{Binding TextOrderEntry}" />
<Entry
x:Name="EntryMachineNumber"
Placeholder="Machine Number"
Text="{Binding TextMachineEntry}" />
And this is where I control the even which is placed at view.cs
public ProductionOrderPage()
{
InitializeComponent();
BindingContext = App.Locator.ProductionOrderPageVM;
EntryOrderNumber.Completed += EntryOrderNumber_Completed;
EntryMachineNumber.Completed += EntryMachineNumber_Completed;
EntryTotalPosition.Completed += EntryTotalPosition_Completed;
}
private void EntryMachineNumber_Completed(object sender, EventArgs e)
{
EntryMachineNumber.Unfocus();
EntryTotalPosition.Focus();
}
private void EntryOrderNumber_Completed(object sender, EventArgs e)
{
EntryOrderNumber.Unfocus();
EntryMachineNumber.Focus();
}
My problem is : While the Entry (Text field) has focused , the Completed event has been triggered which resulting in the focus will go to another field continuously as per set in the Completed event.
the apps being debugged and deployed onto emulator
using MVVMlight
Thanks a lot
using soft keyboard instead of hardware keyboard solve this problems. Weird.
Enabling soft keyboard : Visual Studio Android Emulator Display Keyboard
I am new in Xamarin and I want to go to another screen from one screen. I have a button in first screen and I want to open another screen after clicking on that button.
How can I do this?
Here is the code I have tried so far:
XAML Layout (FirstXAML.xaml)
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AllControlsDemo.FirstXaml">
<StackLayout>
<Slider x:Name="sldr"
VerticalOptions="CenterAndExpand"
ValueChanged="OnSliderValueChanged" />
<Label x:Name="lblValue"
Text="A simple Label"
Font="Large"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Button x:Name="btnClickme"
Text="Click Me!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
Clicked="OnbtnClickme" />
<Button x:Name="btnSecondXaml"
Text="Second Xaml!"
HorizontalOptions="Center"
VerticalOptions="StartAndExpand"
Clicked="OnbtnSecondXaml" />
</StackLayout>
</ContentPage>
Code of (FirstXAML.xaml.cs)
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace AllControlsDemo
{
public partial class FirstXaml : ContentPage
{
private Label valueLabel;
float count = 0.050f;
private Slider slider;
public FirstXaml ()
{
InitializeComponent ();
valueLabel = this.FindByName<Label>("lblValue");
slider = this.FindByName<Slider> ("sldr");
}
void OnSliderValueChanged(object sender, ValueChangedEventArgs args)
{
valueLabel.Text = ((Slider)sender).Value.ToString("F3");
count = float.Parse(valueLabel.Text);
}
void OnbtnClickme(object sender, EventArgs args)
{
count += 0.050f;
slider.Value = count;
}
void OnbtnSecondXaml(object sender, EventArgs args)
{
// Write code here to move on second Xaml
}
}
}
I am also new on Xamarin. I copied your code and solved your problem.
Try this:
void OnbtnSecondXaml(object sender, EventArgs args)
{
// Write code here to move on second Xaml
Navigation.PushModalAsync(new SecondXaml());
}
This is what NavigationPage is for. You need to wrap FirstXAML inside of a NavigationPage, then you can use the Navigation property to navigate to other pages.
Navigation.PushAsync(page2);
Also, you do not need to use FindByName to assign local variables for controls in your xaml. Any control with a x:name property will automatically be assigned a local variable.
I have button and TimeSpanPicker in XAML.
<Image x:Name="sleepButton" Source="img/Sleep.png"
Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2"
Stretch="None" Tap="sleepButton_Tap"/>
<controls:TimeSpanPicker x:Name="timespanPicker" Step="0:5" Value="0:0"
PickerPageUri="timePickerPage"
Grid.Column="1" Grid.Row="2"
Visibility="Collapsed" IsEnabled="False" />
And here is my code.
private void sleepButton_Tap(object sender, GestureEventArgs e)
{
TimeSpanPicker timespanPicker = new TimeSpanPicker();
timespanPicker.PickerPageUri = new Uri("/MainPage.xaml", UriKind.Relative);
timespanPicker.OpenPicker();
}
Then I click the button do nothing. What I'm doing wrong?
The PickerPageUri is if you have a custom picker control such as a single button to set the date/time, not to show the TimeSpanPicker. You're also creating a new instance of TimeSpanPicker here essentially overriding your xaml:
private void sleepButton_Tap(object sender, GestureEventArgs e)
{
TimeSpanPicker timespanPicker = new TimeSpanPicker();
...
You should just be able to call timespanPicker.OpenPicker();. Not sure if you'll need to enable it, but yes, have the visibility collapsed.
You need to change the PickerPageUri to something other than the MainPage.xaml. The intention is to navigate to another page so that you can use this other page to set the time. The following article should help you with this :-
http://windowsphonegeek.com/articles/WP7-TimeSpanPicker-in-depth
I am a newbie in windows phone app and need to create a small Windows Phone 7 app. The app will perform the following task
App Screen has an image "image1' ,when i press on 'image1' it will shows a second image 'image2'
When I press on image2 it will shows image1 and so on
My XAML code
<Button Click="Button_Click">
<Image Source="resourse/image1.jpg"/>
</Button>
C# code
namespace Test
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// here will shows the 'image2' and also give click event to turn 'image1'
}
}
}
Please help
I would tackle this by having a couple of images in your XAML:
<Button Click="Button_Click">
<Grid>
<Image x:Name="imageOne" Source="resourse/image1.jpg"/>
<Image x:Name="imageTwo" Source="resourse/image2.jpg"
Visibility="Collapsed"/>
</Grid>
</Button>
The use of x:Name causes visual studio to generate a field for each image. The second image is 'collapsed', i.e. hidden.
You click handler then does the following:
private void Button_Click(object sender, RoutedEventArgs e)
{
if (imageOne.Visisbility == Visibility.Visible)
{
imageOne.Visisbility = Visibility.Collapsed
imageTwo.Visisbility = Visibility.Visible
}
else
{
imageOne.Visisbility = Visibility.Visible
imageTwo.Visisbility = Visibility.Collapsed
}
}
On each click it toggled the visibility of each image.
This is easier than changing the Source of the image, which involves URIs etc...