Show Password icon shortens entry field in xaml form - xaml

I've added a show password icon to my entry field to allow for password peaks. I have included the entry field and the image in the same StackLayout. It works exactly as it should except the entry field line is shortened to accommodate the image on the same horizontal plane. I want the entry line to extend to the edge of the screen and the password image to appear above it.
This is how it displays currently:
Here is the xaml snippet for the password entry field and image contained in a StackLayout
<StackLayout x:Name="passwordStack" Orientation="Horizontal">
<Entry
x:Name="passwordEntry"
HorizontalOptions="FillAndExpand"
IsPassword="True"
VerticalOptions="Center">
</Entry>
<Image
x:Name="passwordEye"
Source="show_password_icon"
HorizontalOptions="End"
VerticalOptions="Center"
WidthRequest="30"
HeightRequest="30">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="ShowPassword" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
</StackLayout>

Use a Grid instead of an StackLayout:
<Grid>
<Entry
Grid.Row="0"
Grid.Column="0"
x:Name="passwordEntry"
HorizontalOptions="FillAndExpand"
IsPassword="True"
VerticalOptions="Center">
</Entry>
<Image
Grid.Row="0"
Grid.Column="0"
x:Name="passwordEye"
Source="show_password_icon"
HorizontalOptions="End"
VerticalOptions="Center"
WidthRequest="30"
HeightRequest="30">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="ShowPassword" NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
</Grid>
This way, the Image will overlay the Entry.
A problem about this is that Image will be displayed on top of text if the text is too long. So a better solution would be to build a custom control.

Related

Styling Label inside another control

In Xamarin Forms, having a XAML code: (an example below) is it possible to move the style of the Label and the Image to appplication level style and make it default for all Expander headers (or other containers)?
<xct:Expander>
<xct:Expander.Header>
<StackLayout>
<Label
Margin="20,10,0,10"
FontAttributes="Bold"
HorizontalOptions="StartAndExpand"
Text="ABCD"
TextTransform="Uppercase"
VerticalOptions="Center" />
<Image
Margin="0,0,20,0"
HorizontalOptions="End"
VerticalOptions="Center">
<Image.Source>
<FontImageSource
FontFamily="{StaticResource Font_FASolid}"
Glyph="{x:Static fonts:FASolid.ChevronDown}"
Size="{StaticResource MediumFontSize}" />
</Image.Source>
</Image>
</StackLayout>
</xct:Expander.Header>
</xct:Expander>
What I would like to have in my xaml finally is just:
<xct:Expander>
<xct:Expander.Header>
<StackLayout>
<Label Text="ABCD"/>
<Image>
<Image.Source>
<FontImageSource/>
</Image.Source>
</Image>
</StackLayout>
</xct:Expander.Header></xct:Expander>

Not able to close the popup on click event in Xamarin Forms

I have used Rg.Plugins.Popup.
I have aligned close button which is aligned at top right corner 50% outside the window from right and top side as shown in below image.
Now it is showing as per expected design but issue is when I tap on it, only inward part of close button get clicked and outward part is not clickable. So not able to close popup till the time we click that inward part of Close button.
I am sharing my code for more idea.
<ScrollView Orientation="Horizontal">
<AbsoluteLayout HorizontalOptions="Center"
VerticalOptions="Center"
Padding="0,0,0,0"
Margin="0,0,0,0"
Opacity="1">
<Frame AbsoluteLayout.LayoutBounds="0,0,1,1"
IsClippedToBounds="True"
AbsoluteLayout.LayoutFlags="All"
HasShadow="False"
x:Name="outframe"
Margin="0"
CornerRadius="15"
Padding="0"
OutlineColor="#ffffff"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal"
x:Name="stkVideo"
Padding="0">
<Image x:Name="ximage"
Aspect="AspectFill"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="#4A4541" />
<video:VideoPlayer x:Name="trainingPlayer"
DisplayControls="True"
FillMode="ResizeAspectFill"
FlowDirection="LeftToRight"
Volume="100"
Grid.Row="0"
IsVisible="false">
</video:VideoPlayer>
</StackLayout>
</Frame>
<ContentView AbsoluteLayout.LayoutBounds="0.50, 0.50, -1, -1"
AbsoluteLayout.LayoutFlags="PositionProportional">
<Image Source="Play.png"
HeightRequest="{OnIdiom Phone=70,Tablet=85}"
WidthRequest="{OnIdiom Phone=70,Tablet=85}"
Aspect="AspectFit"
VerticalOptions="Center"
HorizontalOptions="Center"
x:Name="icnplay" />
<ContentView.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped_1" />
</ContentView.GestureRecognizers>
</ContentView>
<ContentView AbsoluteLayout.LayoutBounds="1.04, -0.09, -1, -1"
AbsoluteLayout.LayoutFlags="PositionProportional" >
<Image Source="close.png"
HeightRequest="{OnIdiom Phone=35,Tablet=45}"
WidthRequest="{OnIdiom Phone=35,Tablet=45}"
Aspect="AspectFit">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Image.GestureRecognizers>
</Image>
<ContentView.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</ContentView.GestureRecognizers>
</ContentView>
</AbsoluteLayout>
</ScrollView>
What code changes do I need to do so that popup get close when user will click on Close button part which is outside the window as well?
The issue is the close button lies outside the bounds of the <AbsoluteLayout>. One solution involves a few steps:
Make the AbsoluteLayout larger by some amount
Add a margin to the video player Frame equal to how much larger the AbsoluteLayout was made
Update the position of the close button to remain in the top right corner of the video player Frame
Now the close button is contained within the AbsoluteLayout and the entire close button area will receive and raise events for taps/clicks.
I guess that you want to achieve this:
Clicking outside the yellow frame will close the everything.
The red part has a GestureRecognizer
You can achieve this by using a Grid or a Absolute layout, these views allow you to "stack" or add layers to the UI.
Code example:
<AbsoluteLayout
BackgroundColor="Green"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<StackLayout AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All">
<Button Clicked="Button_Clicked" Text="Coso" />
<Button Clicked="Button_Clicked_1" Text="Show popup" />
</StackLayout>
<Frame
x:Name="closeFrame"
AbsoluteLayout.LayoutBounds="1,1,1,1"
AbsoluteLayout.LayoutFlags="All"
BackgroundColor="Red"
IsVisible="false">
<Frame.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="TapGestureRecognizer_Tapped" />
</Frame.GestureRecognizers>
</Grid>
<Frame
x:Name="popupGrid"
AbsoluteLayout.LayoutBounds="0.5,0.5,0.5,0.5"
AbsoluteLayout.LayoutFlags="All"
BackgroundColor="Yellow"
IsVisible="false">
<Label Text="Close ouside this" TextColor="Black" />
</Frame>
</AbsoluteLayout>
In code behind you turn the visibile on/off of the element

Placing UI elements "on top of each other" using FlexLayout in Xamarin.Forms

My goals:
Place an Editor inside of a Frame, and the editor never expand outside of the frame, no matter how much text is supplied.
Place an ActivityIndicator 'inside' a Button (and make the Button text not visible when IsBusy).
Make it relative for different sized devices.
My questions
Is there a way to make these controls appear 'on top' of each other using FlexLayout?
Could there be another, more appropriate, layout for my problem?
Current setup:
What I'd like it to look like:
The current XAML
<!-- This is where the main content on the slide up menu starts -->
<Frame
Grid.Row="1"
BorderColor="white"
CornerRadius="0"
HasShadow="True"
OutlineColor="White">
<FlexLayout
AlignItems="Center"
Direction="Column"
JustifyContent="SpaceEvenly">
<!-- Title -->
<Label
Grid.Row="0"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Text="{util:Translate Viewtitle}" />
<!-- Scrollable text -->
<ScrollView
x:Name="ActionViewScroller"
Grid.Row="1"
Margin="10"
HorizontalOptions="Fill"
VerticalOptions="Center"
VerticalScrollBarVisibility="Always">
<Label Text="{Binding ActionText}" />
</ScrollView>
<!-- Text box for optional notes -->
<Frame
Grid.Row="2"
Margin="10"
BackgroundColor="White"
BorderColor="LightGray"
CornerRadius="0"
FlexLayout.Gorw="1"
HasShadow="False"
WidthRequest="280" />
<Editor
x:Name="ActionViewNotes"
Grid.Row="2"
Margin="15"
AutoSize="TextChanges"
FlexLayout.Grow="1"
HorizontalOptions="FillAndExpand"
IsSpellCheckEnabled="True"
Keyboard="Default"
MaxLength="150"
Placeholder="{util:Translate PlaceholderText}"
Text="{Binding ConsentNotes, Mode=OneWayToSource}"
VerticalOptions="Center"
WidthRequest="280" />
<!-- Submit Button -->
<Button
Grid.Row="3"
AlignSelf="Stretch"
Command="{Binding DoSomething}"
CommandParameter="{Binding Source={Reference TheNotes}, Path=Text}"
HeightRequest="70"
HorizontalOptions="FillAndExpand"
IsVisible="{Binding IsBusy, Converter={StaticResource NegateBooleanConverter}}"
Style="{StaticResource TertiaryButtonStyle}"
Text="{util:Translate DoSomethingText}"
WidthRequest="350" />
<ActivityIndicator
Grid.Row="3"
Margin="5"
HorizontalOptions="Center"
IsRunning="{Binding IsBusy}"
IsVisible="{Binding IsBusy}"
Style="{DynamicResource BaseActivityIndicatorStyle}" />
</FlexLayout>
</Frame>
1.Is there a way to make these controls appear 'on top' of each other using FlexLayout?
Yes, you can put the editor on top of Frame in your case. It is the same as you put a Frame inside a Flexlayout. I added some backgroundColor to the controls to make it clear.
Here is a example of put the editor inside Frame:
<StackLayout>
<!-- Place new controls here -->
<Frame
Grid.Row="1"
BorderColor="white"
CornerRadius="0"
HasShadow="True"
OutlineColor="White">
<FlexLayout
AlignItems="Center"
Direction="Column"
JustifyContent="SpaceEvenly">
<!-- Title -->
<Label
Grid.Row="0"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
BackgroundColor="Green"
Text=" Viewtitle" />
<!-- Scrollable text -->
<ScrollView
x:Name="ActionViewScroller"
Grid.Row="1"
Margin="10"
HorizontalOptions="Fill"
VerticalOptions="Center"
VerticalScrollBarVisibility="Always">
<Label Text="123" />
</ScrollView>
<!-- Text box for optional notes -->
<Frame
Grid.Row="2"
Margin="10"
BorderColor="LightGray"
CornerRadius="0"
FlexLayout.Grow="1"
HasShadow="False"
WidthRequest="280"
BackgroundColor="Red">
<!-- Put your Editor inside Frame here -->
<Editor
x:Name="ActionViewNotes"
Grid.Row="2"
Margin="15"
AutoSize="TextChanges"
FlexLayout.Grow="1"
HorizontalOptions="FillAndExpand"
IsSpellCheckEnabled="True"
Keyboard="Default"
MaxLength="150"
Placeholder="PlaceholderText"
VerticalOptions="Center"
WidthRequest="280"
BackgroundColor="AliceBlue"/>
</Frame>
</FlexLayout>
</Frame>
</StackLayout>
2.Could there be another, more appropriate, layout for my problem?
There are several ways to achieve the layout for your problem. You can use StackLayout,AbsoluteLayout,RelativeLayout,Grid and so on. In my opinion, which to choose depending on yourself. Each way has its own advantages. Flexlayout is more conveniently to arrange its children horizontally and vertically in a stack.
You can refer to the official documents about layout.There are several demos similar with your layout and you can get the advantages of each layout option from there.
Layouts

Add shadow to a Label - Xamarin.Forms

I would like to add drop shadow to a Label. This label is overlapped in the Page, like an always visible control that opens a filtering page.
Please find a gif attached with my screen:
Here's my XAML:
<!-- **** Filter button **** -->
<Label
Margin="0,0,10,10"
WidthRequest="50"
HeightRequest="50"
HorizontalOptions="End"
VerticalOptions="End"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="30"
Style="{DynamicResource FilterAction}"
Text=""
BackgroundColor="{StaticResource ComplementColor}"
FontFamily="{x:Static artina:FontAwesome.FontName}"
TextColor="White">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding btn_open_filter_businesses_click}" />
</Label.GestureRecognizers>
</Label>
<templates:Badge
BadgeText="{Binding number_of_filters_selected}"
BadgeTextColor="White"
BadgeBackgroundColor="#1DBDFF"
HorizontalOptions="End"
VerticalOptions="End"
TranslationX="-4"
TranslationY="-4"
IsVisible="{Binding number_of_filters_selected, Converter={StaticResource filterVis}"
x:Name="filtersCountBagde">
<templates:Badge.GestureRecognizers>
<TapGestureRecognizer Command="{Binding btn_open_filter_businesses_click}" />
</templates:Badge.GestureRecognizers>
</templates:Badge>
I would like something like Gmail, find the example below:
Any help would be appreciated.
You can use Xamarin Effects to achieve a shadow on your button. There is a code sample that you can download here which should get you started:
Shadow Effect
It will involve creating platform-specific implementations for your shadow.
You could also try the idea put forward in this similar question.

keyboard popup its hide last row of grid

I have using AppCompact Themes in xamarin forms android when keyboard popup its hide last row of grid
Before Keyboard Popup see Image
Below is my code. I've created the grid having title, description. I want to show the camera icon and its bar above the keyboard when it comes and go back to the bottom of the screen when the keyboard hides.
<Grid RowSpacing="0" VerticalOptions="FillAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<StackLayout
Grid.Row="0"
Padding="10,8"
BackgroundColor="White"
HorizontalOptions="FillAndExpand"
Orientation="Horizontal">
<Entry
x:Name="GeneralPostTitle"
Margin="10,10,10,0"
FontSize="20"
HorizontalOptions="FillAndExpand"
Placeholder="Title"
PlaceholderColor="Gray"
TextColor="Black"
VerticalOptions="End" />
</StackLayout>
<StackLayout
Grid.Row="1"
Padding="10,0"
BackgroundColor="White"
HorizontalOptions="FillAndExpand"
Spacing="0"
VerticalOptions="FillAndExpand">
<StackLayout Padding="0" VerticalOptions="Fill">
<customRenderer:PlaceholderEditor
x:Name="EditorDescription"
Margin="10,10,10,0"
FontSize="22"
HeightRequest="130"
HorizontalOptions="Fill"
Placeholder="Add Description"
PlaceholderTextColor="Gray"
TextColor="Gray" />
</StackLayout>
<ScrollView Padding="10" Orientation="Horizontal">
<StackLayout
x:Name="Images"
HorizontalOptions="FillAndExpand"
Orientation="Horizontal"
Spacing="5" />
</ScrollView>
</StackLayout>
<StackLayout
Grid.Row="2"
Padding="20,0"
BackgroundColor="#FAFAFA">
<Image
Aspect="AspectFit"
HeightRequest="40"
HorizontalOptions="StartAndExpand"
WidthRequest="30">
<Image.Source>
<OnPlatform
x:TypeArguments="ImageSource"
Android="camera"
WinPhone="Icons/camera.png"
iOS="Icons/camera.png" />
</Image.Source>
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="ImagePost_OnTapped" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</Grid>
After Keyboard Popup see Image
You need to set SoftInput to AdjustResize in order for Android to resize the views so they stay visible. In Forms, you can do this with the platform specifics feature in Forms 2.3.3.
Check out this Gist on how to do this in OnCreate(). Note the workaround that's needed to remove an underlay added to the status bar in API 21+.