本文整理汇总了C#中Xamarin.Forms.TapGestureRecognizer类的典型用法代码示例。如果您正苦于以下问题:C# TapGestureRecognizer类的具体用法?C# TapGestureRecognizer怎么用?C# TapGestureRecognizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TapGestureRecognizer类属于Xamarin.Forms命名空间,在下文中一共展示了TapGestureRecognizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnimateWithAction
public static void AnimateWithAction(this Label label, Command command = null, ScaleType type = ScaleType.After)
{
var tapGesture = new TapGestureRecognizer ();
tapGesture.Tapped += async (sender, args) => {
switch (type) {
case ScaleType.First:
command?.Execute (null);
await label.ScaleTo (0.75, 100, Easing.CubicOut);
await label.ScaleTo (1, 100, Easing.CubicIn);
break;
case ScaleType.Midle:
await label.ScaleTo (0.75, 100, Easing.CubicOut);
command?.Execute (null);
await label.ScaleTo (1, 100, Easing.CubicIn);
break;
case ScaleType.After:
await label.ScaleTo (0.75, 100, Easing.CubicOut);
await label.ScaleTo (1, 100, Easing.CubicIn);
command?.Execute (null);
break;
default:
break;
}
};
label.GestureRecognizers.Add (tapGesture);
}
示例2: MyToolBar
public MyToolBar(string labelText, string leftIconText, string rightIconText)
{
_toolbarInfoLabel = new Label {
Text = labelText,
TextColor = Color.White,
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center,
};
LeftIcon = new Label {
Text = leftIconText,
TextColor = Color.White,
HorizontalOptions = LayoutOptions.EndAndExpand,
};
LeftIconGestureRecognizer = new TapGestureRecognizer ();
RightIcon = new Label {
Text = rightIconText,
TextColor = Color.White,
HorizontalOptions = LayoutOptions.End
};
RightIconGestureRecognizer = new TapGestureRecognizer ();
Children.Add (_toolbarInfoLabel);
Children.Add (LeftIcon);
Children.Add (RightIcon);
BackgroundColor = Color.Silver;
HeightRequest = 20;
Orientation = StackOrientation.Horizontal;
Padding = new Thickness (12, 12, 12, 12);
}
示例3: ExpandableCell
public ExpandableCell(Layout header, Layout body, Layout footer)
{
this.Padding = 0;
this.Spacing = 0;
this.Children.Add (header);
this.Children.Add (body);
this.Children.Add (footer);
this.body = body;
this.IsClippedToBounds = true;
var gestureRecognizer = new TapGestureRecognizer () { };
gestureRecognizer.Tapped += (sender, e) => {
double start = expanded ? bodyHeight : 0; // the starting height
double offset = expanded ? -bodyHeight : bodyHeight; // the change over the animation
expanded = !expanded;
this.body.Animate (
name: "set height",
animation: new Xamarin.Forms.Animation((val) => {
this.body.HeightRequest = start + offset*val;
}),
length: 250,
easing: Easing.CubicInOut
);
};
header.GestureRecognizers.Add (gestureRecognizer);
}
示例4: BuildLayout
public void BuildLayout()
{
mainStack.Spacing = 20;
mainStack.Padding = 50;
mainStack.VerticalOptions = LayoutOptions.Center;
userNameEntry.Placeholder = "Username";
passwordEntry.Placeholder = "Password";
passwordEntry.IsPassword = true;
Button loginButton = new Button();
loginButton.Text = "Login";
loginButton.TextColor = Color.Black;
loginButton.BackgroundColor = Color.FromHex("77D065");
var tapGesture = new TapGestureRecognizer { Command = new Command(LoginTap)};
loginButton.GestureRecognizers.Add(tapGesture);
mainStack.Children.Add(userNameEntry);
mainStack.Children.Add(passwordEntry);
mainStack.Children.Add(loginButton);
}
示例5: ActivateOrDeactivateMenu
private void ActivateOrDeactivateMenu()
{
if (isMenuAnimationWorking)
return;
else
isMenuAnimationWorking = true;
Rectangle menuRectangle;
Rectangle midRectangle;
if (!IsMenuOpen) {
menuRectangle = new Rectangle (new Point (MyDevice.GetScaledSize(mMenuWidth), 0), new Size (mMenuLayout.Bounds.Width, mMenuLayout.Bounds.Height));
midRectangle = new Rectangle (new Point (MyDevice.GetScaledSize (mMenuWidth), 0), new Size (mMidLayout.Bounds.Width, mMidLayout.Bounds.Height));
mainRelativeLayout.Children.Add (InputBlockerForSwipeMenu,
Constraint.Constant (MyDevice.GetScaledSize (mMenuWidth)),
Constraint.Constant (0)
);
var tapRecognizer = new TapGestureRecognizer ();
if (InputBlockerForSwipeMenu.GestureRecognizers.Count == 0) {
tapRecognizer.Tapped += (sender, e) => {
ActivateOrDeactivateMenu();
};
}
InputBlockerForSwipeMenu.GestureRecognizers.Add(tapRecognizer);
} else {
menuRectangle = new Rectangle (new Point (MyDevice.GetScaledSize (0), 0), new Size (mMenuLayout.Bounds.Width, mMenuLayout.Bounds.Height));
midRectangle = new Rectangle (new Point (0, 0), new Size (mMidLayout.Bounds.Width, mMidLayout.Bounds.Height));
mainRelativeLayout.Children.Remove (InputBlockerForSwipeMenu);
}
mMenuLayout.TranslateTo (menuRectangle.X,menuRectangle.Y, MyDevice.AnimationTimer, Easing.Linear).ContinueWith(antecendent => isMenuAnimationWorking=false);
mMidLayout.TranslateTo (midRectangle.X,midRectangle.Y, MyDevice.AnimationTimer, Easing.Linear);
IsMenuOpen = !IsMenuOpen;
}
示例6: HomeView
public HomeView()
{
InitializeComponent();
#region ChooseView
TapGestureRecognizer chooseTapGestureRecognizer = new TapGestureRecognizer();
chooseTapGestureRecognizer.Tapped += (async (o2, e2) =>
{
App.MealManager.Reset();
var page = new ChooseView();
NavigationPage.SetHasBackButton(page, true);
await Navigation.PushAsync(page, false);
});
ChooseStack.GestureRecognizers.Add(chooseTapGestureRecognizer);
#endregion
#region OverviewView
TapGestureRecognizer overviewTapGestureRecognizer = new TapGestureRecognizer();
overviewTapGestureRecognizer.Tapped += (async (o2, e2) =>
{
var page = new OverviewView();
NavigationPage.SetHasBackButton(page, true);
await Navigation.PushAsync(page, false);
});
OverviewStack.GestureRecognizers.Add(overviewTapGestureRecognizer);
#endregion
}
示例7: CreateOrRemoveGestureRecognizer
private void CreateOrRemoveGestureRecognizer()
{
if (Command == null)
{
if (_tapGestureRecognizer == null) return;
GestureRecognizers.Remove(_tapGestureRecognizer);
_tapGestureRecognizer = null;
}
else
{
if (_tapGestureRecognizer != null) return;
_tapGestureRecognizer = new TapGestureRecognizer
{
Command = new RelayCommand(p =>
{
if (Command != null)
Command.Execute(CommandParameter ?? p);
}, p => Command == null || Command.CanExecute(CommandParameter ?? p))
};
GestureRecognizers.Add(_tapGestureRecognizer);
}
}
示例8: ConfigSpringboard
public ConfigSpringboard()
{
NavigationPage.SetHasNavigationBar (this, false);
Grid configGrid = new Grid {
BackgroundColor = Colours.BG_DARK,
Padding = new Thickness(10),
RowDefinitions = {
new RowDefinition {
Height = new GridLength(150, GridUnitType.Absolute)
}
},
ColumnDefinitions = {
new ColumnDefinition {
Width = new GridLength(1, GridUnitType.Star)
},
new ColumnDefinition {
Width = new GridLength(1, GridUnitType.Star)
}
}
};
HomeButton UC = new HomeButton (IconLabel.Icon.FAUser, "YOUR INFO", Colours.USERCONFIG_LIGHT, Colours.USERCONFIG_MEDIUM);
HomeButton AC = new HomeButton (IconLabel.Icon.FABell, "ALERTS CONFIG", Colours.ALERTSCONFIG_LIGHT, Colours.ALERTSCONFIG_MEDIUM);
var alertConfigTapGestureRecognizer = new TapGestureRecognizer ();
alertConfigTapGestureRecognizer.Tapped += async (s, e) => {
if (AC.IsEnabled) {
AC.IsEnabled = false;
await AC.ScaleTo(.8, 100);
await AC.ScaleTo(1, 100);
await Navigation.PushAsync (await AlertConfigContainer.CreateAlertConfigContainer());
AC.IsEnabled = true;
}
};
AC.GestureRecognizers.Add (alertConfigTapGestureRecognizer);
var userConfigTapGestureRecognizer = new TapGestureRecognizer ();
userConfigTapGestureRecognizer.Tapped += async (s, e) => {
if (UC.IsEnabled) {
UC.IsEnabled = false;
await UC.ScaleTo(.8, 100);
await UC.ScaleTo(1, 100);
await Navigation.PushAsync (await YourInfoPageContainer.CreateYourInfoPageContainer());
UC.IsEnabled = true;
}
};
UC.GestureRecognizers.Add (userConfigTapGestureRecognizer);
configGrid.Children.Add (UC, 0, 0);
configGrid.Children.Add (AC, 1, 0);
ScrollView scrollView = new ScrollView {
Orientation = ScrollOrientation.Vertical,
Content = configGrid,
VerticalOptions = LayoutOptions.FillAndExpand
};
Content = scrollView;
}
示例9: GridBarChartPage
public GridBarChartPage()
{
InitializeComponent();
List<View> views = new List<View>();
TapGestureRecognizer tapGesture = new TapGestureRecognizer();
tapGesture.Tapped += OnBoxViewTapped;
// Create BoxView elements and add to List.
for (int i = 0; i < COUNT; i++)
{
BoxView boxView = new BoxView
{
Color = Color.Accent,
HeightRequest = 300 * random.NextDouble(),
VerticalOptions = LayoutOptions.End,
StyleId = RandomNameGenerator()
};
boxView.GestureRecognizers.Add(tapGesture);
views.Add(boxView);
}
// Add whole List of BoxView elements to Grid.
grid.Children.AddHorizontal(views);
// Start a timer at the frame rate.
Device.StartTimer(TimeSpan.FromMilliseconds(15), OnTimerTick);
}
示例10: ConnexionPage
public ConnexionPage()
{
InitializeComponent ();
personConnecte = "";
Poster.Source = ImageSource.FromFile("NoOne.jpg");
var profilImage = new TapGestureRecognizer ();
profilImage.Tapped += async (sender, e) => {
var action = await DisplayActionSheet("Choisir une action", "Annuler", null, "Phototheque", "Prendre une photo");
if (action == "Phototheque")
{
await SelectPicture();
}
else if (action == "Prendre une photo")
{
await TakePicture();
}
else
{
Poster.Source = ImageSource.FromFile ("NoOne.jpg");
}
};
emailEntry.Text = "";
Poster.GestureRecognizers.Add(profilImage);
}
示例11: Springboard
public Springboard ()
{
InitializeComponent ();
var tapFirst = new TapGestureRecognizer();
tapFirst.Tapped += async (s, e) =>
{
//firstImage.Opacity = .5; // dim the image for user feedback when tapped
//await Task.Delay(100);
//firstImage.Opacity = 1;
await this.Navigation.PushAsync(new FirstPage());
};
FirstImage.GestureRecognizers.Add(tapFirst);
var tapSecond = new TapGestureRecognizer();
tapSecond.Tapped += async (s, e) =>
{
await this.Navigation.PushAsync(new SecondPage());
};
SecondImage.GestureRecognizers.Add(tapSecond);
var tapThird = new TapGestureRecognizer();
tapThird.Tapped += async (s, e) =>
{
await this.Navigation.PushAsync(new ThirdPage());
};
ThirdImage.GestureRecognizers.Add(tapThird);
}
示例12: SetupEventHandlers
private void SetupEventHandlers()
{
firstNameEntry.Completed += (object sender, EventArgs e) =>
{
lastNameEntry.Focus();
};
lastNameEntry.Completed += (object sender, EventArgs e) =>
{
lastNameEntry.Focus();
};
usernameEntry.Completed += (object sender, EventArgs e) =>
{
usernameEntry.Focus();
};
passwordEntry.Completed += (object sender, EventArgs e) =>
{
passwordEntry.Focus();
};
cancelButtonTapped = new TapGestureRecognizer();
cancelButtonTapped.Tapped += (object sender, EventArgs e) =>
{
Navigation.PopModalAsync();
};
cancelButton.GestureRecognizers.Add(cancelButtonTapped);
}
示例13: Option
public Option()
{
Label = new Label {
Text = "Option",
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.Center
};
PagePanel = new PagePanel {
HorizontalOptions = LayoutOptions.End,
Pages = new List<View> {
new Image (),
new Image ()
}
};
var layout = new StackLayout {
Orientation = StackOrientation.Horizontal,
Children = {
Label,
PagePanel
}
};
var tapGestureRecognizer = new TapGestureRecognizer ();
tapGestureRecognizer.Tapped += (sender, e) => OnTapped ();
GestureRecognizers.Add (tapGestureRecognizer);
Content = layout;
SetImageState ();
SetLabelState ();
}
示例14: ArticlePage
public ArticlePage()
{
InitializeComponent();
this.BackgroundColor = Color.White;
BindingContext = new ArticleViewModel();
var tgr = new TapGestureRecognizer ();
tgr.Tapped +=(s,e)=>ExpandLabelClicked();
lblExpand.GestureRecognizers.Add(tgr);
artStackLayout.SizeChanged += ArticleStackLayout_SizeChanged;
#region WebView Navigation
webView1.Navigating += (s, e) =>
{
if (e.Url.StartsWith("http") || e.Url.StartsWith("mailto"))
{
try
{
var uri = new Uri(e.Url);
Device.OpenUri(uri);
}
catch (Exception)
{
}
e.Cancel = true;
}
};
#endregion
}
示例15: AddMoodOptions
void AddMoodOptions()
{
//hardcoded to be 3x3
int rows = 3;
int cols = 3;
//we get all the filenames to prepare to display the images
var filenames = new List<string>(vm.moods.Keys);
//images cannot handle taps out of the box
var tapRecognizer = new TapGestureRecognizer();
//tapRecognizer.NumberOfTapsRequired = 1;
tapRecognizer.Tapped += OnTapGestureRecognizerTapped;
//to iterate through every image
int k = 0;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++, k++)
{
var moodImg = new Image { Source = filenames[k], Opacity = CONST.DEFAULT_OPACITY };
moodImg.GestureRecognizers.Add(tapRecognizer);
grdMoods.Children.Add(moodImg, j, i);
}
}
}