I am trying to display , display alert when I click on "OnLogOut" but is it not woring and I cannot see why
<StackLayout Grid.Row="1" BackgroundColor="White" HorizontalOptions="FillAndExpand" Orientation="Vertical" VerticalOptions="FillAndExpand" Spacing="30" Padding="0,0,0,0">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<!--Le text est dans la classe-->
<Label x:Name="myemail" Text="" TextColor="#36688D" Font="Bold,Italic,20" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label HorizontalOptions="Center"
TextColor="#36688D"
FontSize="15"
Text="Log Out" x:Name="mylogout">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="OnLogOut" />
</Label.GestureRecognizers>
</Label>
</StackLayout>
</StackLayout>
Here is my c# code:
public async void OnLogOut(object sender, EventArgs args)
{
Console.WriteLine("Log out is tapped");
await DisplayAlert("Email", "Your email please", "✔");
}
thanks in advance
Related
I am having some issues having my back button properly pop my modal after a user acknowledged that they will lose their changes if they do so. I suppose the issue lies in how to properly await the async method within a method that cannot be async due to how it is coded.
In my code behind I have the following method:
protected override bool OnBackButtonPressed()
{
base.OnBackButtonPressed();
Task<bool> confirm = DisplayAlert("Are you sure?", "All unsaved changes will be lost", "I'm Sure", "Cancel");
confirm.ContinueWith(x =>
{
if(x.Result)
{
var task = Navigation.PopModalAsync();
task.Wait();
}
});
return true;
}
I can see that it does properly hit my breakpoint inside if the user has clicked "I'm Sure". However, after doing that the modal still remains on the page.
I call my modal using the following method (it is wrapped in a NavigationPage as I wanted to be able to leverage Toolbar items, if this is an anti pattern please let me know)
private async void EditSwipeItem_Invoked(object sender, EventArgs e)
{
var unitOfWork = container.Resolve<IUnitOfWork>();
var invoked = sender as SwipeItem;
var element = invoked.BindingContext as InventoryModel;
await Navigation.PushModalAsync(new NavigationPage(new AddEditInventoryList(true, "8dc9e483-1d63-4629-b386-680ad7c9a324", element.InventoryId, unitOfWork)));
}
The code for the backbutton is based off of what I wrote for the CancelToolBar_Clicked, and it works correctly (That is, the modal is popped after the user acknowledges the prompt).
private async void CancelToolBar_Clicked(object sender, EventArgs e)
{
bool confirm = await DisplayAlert("Are you sure?", "All unsaved changes will be lost", "I'm Sure", "Cancel");
if(confirm)
await Navigation.PopModalAsync();
}
Edit:
This is what my XAML looks like:
<?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="Invenutory.Views.Inventory.AddEditInventoryList">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Save"
Order="Primary"
Clicked="SaveToolBarItem_Clicked"
Priority="1"/>
<ToolbarItem Text="Cancel"
Order="Secondary"
Clicked="CancelToolBar_Clicked"
Priority="0"/>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Padding="20">
<Frame HorizontalOptions="FillAndExpand"
VerticalOptions="Start"
Padding="20"
CornerRadius="8"
BorderColor="AliceBlue">
<StackLayout
HorizontalOptions="FillAndExpand"
VerticalOptions="StartAndExpand">
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"
Orientation="Vertical">
<Label Text="Name: " HorizontalOptions="Start" VerticalOptions="Start" />
<Entry HorizontalOptions="FillAndExpand" VerticalOptions="Start" Text="{Binding Name, Mode=TwoWay}" IsSpellCheckEnabled="True" IsTextPredictionEnabled="True" />
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"
Orientation="Vertical">
<Label Text="Description: " HorizontalOptions="StartAndExpand" VerticalOptions="Start"/>
<Editor HorizontalOptions="FillAndExpand" VerticalOptions="Start" Text="{Binding Description, Mode=TwoWay}" IsSpellCheckEnabled="True" IsTextPredictionEnabled="True" />
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"
Orientation="Vertical">
<Label Text="Count: " HorizontalOptions="Start" VerticalOptions="Start"/>
<Entry Keyboard="Numeric" HorizontalOptions="FillAndExpand" VerticalOptions="Start" Text="{Binding Count, Mode=TwoWay}" />
</StackLayout>
</StackLayout>
</Frame>
<Frame HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="20" CornerRadius="8" BorderColor="AliceBlue">
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Image HorizontalOptions="FillAndExpand" VerticalOptions="Start" HeightRequest="150" Aspect="AspectFit" BackgroundColor="Gray" Source="{Binding CapturedPhoto}" />
<Button Text="Take Photo" HorizontalOptions="FillAndExpand" VerticalOptions="Start" Command="{Binding TakePhotoCommand, Mode=TwoWay}"/>
</StackLayout>
</Frame>
</StackLayout>
</ContentPage.Content>
</ContentPage>
I was able to solve this by updating my inner .ContinueWith to look as follows:
confirm.ContinueWith(x =>
{
if(x.Result)
{
MainThread.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopModalAsync();
});
}
});
I have a registration page. First the user enters his informations like email, password, weight, height...
After the user has filled out this form I want to store information most important ones email and password.
Then I want to use this data in the LoginPage( named in MainPage in my case).
So I need to store and then check this info in loginpage what user enters true or false
I am adding my registration page and others code. If you have any idea or suggestions I am open for them.
<?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="HealNow.Signup"
NavigationPage.HasNavigationBar="False">
<ContentPage.Resources>
<ResourceDictionary>
<LinearGradientBrush x:Key="Theme" EndPoint="0,1">
<GradientStop Color="#48b6a6" Offset="0.1" />
<GradientStop Color="#2b78d4" Offset="1.0" />
</LinearGradientBrush>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0">
</OnPlatform>
</ContentPage.Padding>
<StackLayout Background="{StaticResource Theme}">
<StackLayout Background="{StaticResource Theme}" >
</StackLayout>
<StackLayout Margin="0,35,0,0">
<Image HorizontalOptions="Center" HeightRequest="60" WidthRequest="60" Source="heartbeatt.png" ></Image>
</StackLayout>
<StackLayout Padding="0" Margin="10,20,10,0" HorizontalOptions="FillAndExpand" >
<Frame BackgroundColor="Transparent" HeightRequest="600" Padding="0" Margin="0">
<StackLayout>
<StackLayout Padding="0" Margin="15,10">
<Frame BackgroundColor="Transparent" BorderColor="White" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="user.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry x:Name ="email" Placeholder="Email" TextColor="#666666" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0" Completed="OnChange"/>
</StackLayout>
</Frame>
<Frame BackgroundColor="Transparent" BorderColor="White" Margin="0,12,0,0" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="broken.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry x:Name ="password" Placeholder="Password" IsPassword="True" TextColor="White" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0" Completed="OnChange"/>
</StackLayout>
</Frame>
<Frame BackgroundColor="Transparent" BorderColor="White" Margin="0,12,0,0" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="babyy.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry Placeholder="Date of Birth" TextColor="White" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
</StackLayout>
</Frame>
<Frame BackgroundColor="Transparent" Margin="0,12,0,0" BorderColor="White" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="barrr.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry Placeholder="Weight" TextColor="#666666" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
</StackLayout>
</Frame>
<Frame BackgroundColor="Transparent" Margin="0,12,0,0" BorderColor="White" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="height.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry Placeholder="Height" TextColor="#666666" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
</StackLayout>
</Frame>
<Button Margin="30" Text="SIGN UP" BackgroundColor="#2a52be" TextColor="White" CornerRadius="30" Clicked="Button_Clicked" />
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
</StackLayout>
</ContentPage>
and it looks like this
Signup.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace HealNow
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Signup : ContentPage
{
public Signup()
{
InitializeComponent();
Application.Current.Properties[email.Text] = password.Text;
if (Application.Current.Properties.ContainsKey("Email"))
{
var email = Application.Current.Properties["Email"] as string;
}
if (Application.Current.Properties.ContainsKey("Password"))
{
var password = Application.Current.Properties["Password"] as string;
}
}
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new MainPage());
}
private void OnChange(object sender, EventArgs e)
{
Application.Current.Properties["Email"] = email.Text;
Application.Current.Properties["Password"] = password.Text;
Application.Current.SavePropertiesAsync();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
}
}
}
MainPage.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="HealNow.MainPage"
NavigationPage.HasNavigationBar="False">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0">
</OnPlatform>
</ContentPage.Padding>
<StackLayout>
<StackLayout.Background>
<LinearGradientBrush x:Name="Theme" EndPoint="0,1">
<GradientStop Color="#48b6a6" Offset="0.1" />
<GradientStop Color="#2b78d4" Offset="1.0" />
</LinearGradientBrush>
</StackLayout.Background>
<StackLayout Margin="0,35,0,0">
<Image HorizontalOptions="Center" HeightRequest="60" WidthRequest="60" Source="heartbeatt.png" ></Image>
</StackLayout>
<StackLayout Padding="0" Margin="10,20,10,0" HorizontalOptions="FillAndExpand" >
<Frame BackgroundColor="Transparent" HeightRequest="600" Padding="0" Margin="0">
<StackLayout>
<StackLayout Padding="0" Margin="15,10">
<Frame BackgroundColor="Transparent" BorderColor="White" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="user.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry x:Name="email2" Placeholder="Email" TextColor="#666666" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
</StackLayout>
</Frame>
<Frame BackgroundColor="Transparent" BorderColor="White" Margin="0,15,0,0" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
<StackLayout Orientation="Horizontal">
<Frame BackgroundColor="Transparent" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
<Image Source="broken.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Entry x:Name="password2" Placeholder="Password" IsPassword="True" TextColor="White" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
</StackLayout>
</Frame>
<StackLayout Orientation="Horizontal">
<CheckBox IsChecked="False" Color="White" />
<Label Text="Remember me" TextColor="White" FontSize="10" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" />
<Label Text="Forgot Password" TextColor="White" HorizontalOptions="EndAndExpand" FontSize="10" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" />
</StackLayout>
<Button Margin="10" Text="SIGN IN" BackgroundColor="#2b78d4" TextColor="White" CornerRadius="30" Clicked="Button_Clicked" />
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Label Text="Still Not Connected ?" TextColor="White" FontSize="10"/>
<Button Margin="0,-17,0,0" Text="Sign Up" TextColor="White" FontAttributes="Bold" FontSize="10" BackgroundColor="Transparent" Clicked="Button_Clicked2" />
</StackLayout>
<StackLayout Margin="0,25,0,0" Padding="0">
<Grid>
<BoxView BackgroundColor="White" HeightRequest="1" WidthRequest="150" HorizontalOptions="Center" VerticalOptions="Center"/>
<Frame BackgroundColor="White" HeightRequest="45" WidthRequest="45" CornerRadius="45" HasShadow="False" BorderColor="White" Margin="0" HorizontalOptions="Center" Padding="0">
<Label Text="OR" TextColor="#666666" FontSize="Small" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
</Frame>
</Grid>
</StackLayout>
<StackLayout Margin="0,25" Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
<Frame BackgroundColor="Transparent" HeightRequest="45" WidthRequest="45" CornerRadius="45" HasShadow="False" BorderColor="White" Margin="0" HorizontalOptions="Center" Padding="0">
<Image Source="https://www.pngitem.com/pimgs/m/44-440455_transparent-background-fb-logo-hd-png-download.png" Aspect="AspectFill" Margin="0"/>
</Frame>
<Frame BackgroundColor="Transparent" HeightRequest="45" WidthRequest="45" CornerRadius="45" HasShadow="False" BorderColor="White" Margin="0" HorizontalOptions="Center" Padding="0">
<Image Source="https://blog.hubspot.com/hubfs/image8-2.jpg" Aspect="AspectFill" Margin="0"/>
</Frame>
</StackLayout>
</StackLayout>
</StackLayout>
</Frame >
</StackLayout>
</StackLayout >
</ContentPage>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace HealNow
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new WelcomePage());
}
private async void Button_Clicked2(object sender, EventArgs e)
{
await Navigation.PushAsync(new Signup());
}
}
}
string email;
string password;
public MainPage()
{
InitializeComponent();
if (Application.Current.Properties.ContainsKey("Email"))
{
email = Application.Current.Properties["Email"] as string;
}
if (Application.Current.Properties.ContainsKey("Password"))
{
password = Application.Current.Properties["Password"] as string;
}
}
I have several images in my XAML as follows (for this example I included two images).
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="{Binding Image1}" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="{StaticResource greyishBrown}"/>
</StackLayout>
StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="{Binding Image2}" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0"
TextColor="{StaticResource greyishBrown}"/>
</StackLayout>
I want to check what image has been clicked by the user. Fort this I'm using ClassId. I have included ClassIds in all images. This has a single method in code behind and I'm accessing classId from there.
But I'm not getting the Id when user clicks an image. I'm new to C# and Xamarin Forms. Could someone help me.
public void SelectedImage(object sender, EventArgs eventArgs)
{
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageSender.ClassId,"OK");
//TODO
}
XAML
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image1" ClassId="Image1" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Asian Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="{StaticResource greyishBrown}" />
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" Padding="0,5,0,5">
<Image x:Name="Image2" ClassId="Image2" Source="tickoff.png" HeightRequest="18">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="SelectedImage"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
<Label Text="Japanese Foods" FontSize="16" HorizontalOptions="Center" Margin="5,0,0,0" TextColor="{StaticResource greyishBrown}"
/>
</StackLayout>
C#
public void SelectedImage(object sender, EventArgs eventArgs)
{
Image image = (Image)sender;
string imageString = image.ClassId;
DisplayAlert("Test", imageString ,"OK");
//TODO
}
After press, the return button on-screen keyboard the listview hide from the iOS screen. The same code is running perfectly on Android. I have create the 30 second video that will help you understand the problem.
The code file and Video can be download from here https://drive.google.com/drive/folders/1Q4O1KexIHvrCX79AR3CesRXJRWM1o2JR?usp=sharing
<ListView x:Name="listViewOrder" ItemTapped="OnActivitySelected" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame HasShadow="True" OutlineColor="Silver" Padding="3">
<Grid BackgroundColor="{Binding RowColour}" ColumnSpacing="2" Padding="2">
<StackLayout Orientation="Horizontal" HeightRequest="35" BackgroundColor="{Binding RowColour}" Padding="10">
<StackLayout Spacing="0" BackgroundColor="{Binding RowColour}" Orientation="Horizontal" HorizontalOptions="Start">
<Label FontSize="Medium" TextColor="#707070" Text="{Binding GFIELD3}" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
</StackLayout>
<StackLayout Spacing="0" BackgroundColor="{Binding RowColour}" Orientation="Horizontal" HorizontalOptions="EndAndExpand">
<Image Aspect="AspectFit" Source = "{Binding ImageStatus}" HorizontalOptions="StartAndExpand" VerticalOptions="Center" HeightRequest = "20" WidthRequest="20" />
</StackLayout>
</StackLayout>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout x:Name="layoutForBluetooth" HeightRequest="200" Padding="5, 5, 5, 5" BackgroundColor="#5DCBEE" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Frame Padding="5,5,5,5" HorizontalOptions="FillAndExpand" OutlineColor="Black" HasShadow="True">
<Grid>
<Label Text="Scan Your Barcode" x:Name="lblDriverNumber" TextColor="Black" FontSize="Medium" HorizontalOptions="FillAndExpand" Margin="0,10" />
<Entry x:Name="txtentry" FontSize="Medium" TextColor="Black" WidthRequest="400" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" />
</Grid>
</Frame>
async void Txtentry_Completed(object sender, EventArgs e)
{
BiendListview(orderID);
}
public void BiendListview(int OID)
{
try
{
List<GenericFields> GN = new List<GenericFields>();
GN = GetDeliveryOrderItems(OID);
if (GN != null)
{
// listViewOrder.BeginRefresh();
listViewOrder.ItemsSource = GN;
// listViewOrder.EndRefresh();
}
}
catch (Exception ex)
{
}
}
Please make a breakpoint to debug your GN's value. From your code:
if (GN != null)
{
// listViewOrder.BeginRefresh();
listViewOrder.ItemsSource = GN;
// listViewOrder.EndRefresh();
}
This if statement will always be true, since you have construct the GN by List<GenericFields> GN = new List<GenericFields>();. It will never be null.
You can try to modify it to:
if (GN.Count != 0)
{
// listViewOrder.BeginRefresh();
listViewOrder.ItemsSource = GN;
// listViewOrder.EndRefresh();
}
I got these five images and I want to change the opacity of the selected Icon to 1 and then set the rest to 0.25.
I got this far, but got no idea how to change the opacity on all of them. All the guides say to x:reference every single image, but as I got multiple that would get weird quickly.
public async void OnSeverityTapped(object sender, EventArgs args)
{
String[] buttons = new String[SeverityValues.Count];
for (int n = 0; n < SeverityValues.Count; ++n)
{
buttons[n] = SeverityValues[n].Name;
}
var res = await this.DisplayActionSheet("Pick Severity", "Cancel", "", buttons);
if (res != "Cancel")
foreach (var item in SeverityValues)
{
if (item.Name == res)
{
Issue.SeverityEx = item.Value;
lbSeverity.Text = item.Name;
return;
}
}
}
Xaml
<!--Severity-->
<Label Grid.Row="0" Grid.Column="0" Text="SEVERITY" XAlign="Start" YAlign="Center" Style="{StaticResource Labelfont}" />
<Label x:Name="lbSeverity" Grid.Column="1" Text="" YAlign="Center" HorizontalOptions="StartAndExpand" Style="{StaticResource Labelfont}" />
<StackLayout Grid.Row="1" Grid.Column="0" Orientation="Horizontal" Spacing="4">
<Image Source="severity_5.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" Opacity="0.4"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Spacing="4">
<Image Source="severity_4.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" Opacity="0.4"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Grid.Row="1" Grid.Column="2" Orientation="Horizontal" Spacing="4">
<Image Source="severity_3.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" Opacity="1"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Grid.Row="1" Grid.Column="3" Orientation="Horizontal" Spacing="4">
<Image Source="severity_2.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" Opacity="0.4"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Grid.Row="1" Grid.Column="4" Orientation="Horizontal" Spacing="4">
<Image Source="severity_1.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" Opacity="0.4"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</StackLayout.GestureRecognizers>
</StackLayout>
Your code behind for changing opacity could look like this:
public void OnSeverityTapped(object sender, EventArgs args)
{
severity5.Opacity = 0.25;
severity4.Opacity = 0.25;
severity3.Opacity = 0.25;
severity2.Opacity = 0.25;
severity1.Opacity = 0.25;
var image = (Image)sender;
image.Opacity = 1;
}
}
and xaml:
<StackLayout>
<Image x:Name="severity5" Source="severity_5.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
<Image x:Name="severity4" Source="severity_4.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
<Image x:Name="severity3" Source="severity_3.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
<Image x:Name="severity2" Source="severity_2.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
<Image x:Name="severity1" Source="severity_1.png" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnSeverityTapped" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>