Hi,
i Want to dismiss the picker when i tap on background or wherever
Now my Hamburger and Picker is overlaping
Hi,
i Want to dismiss the picker when i tap on background or wherever
Now my Hamburger and Picker is overlaping
I'm working on a full screen image page that supports pinch to zoom, pan to move and tap to show captions. I'm basing this on how image viewer works in apps such as Facebook and Yelp. My code is built off Xamarin examples on gesture recognizers, which can be found at https://developer.xamarin.com/guides/xamarin-forms/user-interface/gestures/
My problem is that when the image is zoomed in and I rotate the device, and then zoomed out. The image is off the center. I would really appreciate it very much if someone can help me finish this, so it supports varying device orientations.
using System;
using System.ComponentModel;
using Xamarin.Forms;
namespace TurfDoctor
{
public class FullScreenImagePage : ContentPage
{
double currentScale = 1;
double startScale = 1;
double xOffset = 0;
double yOffset = 0;
double originalWidth;
double originalHeight;
double ScreenWidth;
double ScreenHeight;
PanGestureRecognizer panGesture;
bool showEverything = false;
StackLayout imageDescription;
Button backButton;
BoxView topBox;
Image image;
ContentView imageContainer;
Label indexLabel;
//Label xLabel, yLabel, transXLabel, transYLabel, widthLabel, heightLabel, scaleLabel, screenWidthLabel, screenHeightLabel;
AbsoluteLayout absoluteLayout;
protected override void OnAppearing ()
{
ShowEverything = true;
base.OnAppearing ();
}
protected override bool OnBackButtonPressed ()
{
App.NavPage.BarTextColor = Color.Black; // turn the status bar back to black
return base.OnBackButtonPressed ();
}
public bool ShowEverything
{
set{
showEverything = value;
backButton.IsVisible = showEverything;
imageDescription.IsVisible = showEverything;
topBox.IsVisible = showEverything;
indexLabel.IsVisible = showEverything;
if (!showEverything) {
// hide the status bar by turning it black
App.NavPage.BarTextColor = Color.Black;
imageContainer.GestureRecognizers.Add (panGesture);
} else {
// show the status bar by turning it white
App.NavPage.BarTextColor = Color.White;
imageContainer.GestureRecognizers.Remove (panGesture);
}
}
get{
return showEverything;
}
}
public FullScreenImagePage (String ImageName, string DescriptionText, int index, int count)
{
NavigationPage.SetHasNavigationBar (this, false);
image = new Image {
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
Aspect = Aspect.AspectFill,
Source = ImageName
};
imageContainer = new ContentView {
Content = image
};
var tapGesture = new TapGestureRecognizer ();
tapGesture.Tapped += OnTapped;
imageContainer.GestureRecognizers.Add (tapGesture);
var pinchGesture = new PinchGestureRecognizer ();
pinchGesture.PinchUpdated += OnPinchUpdated;
imageContainer.GestureRecognizers.Add (pinchGesture);
panGesture = new PanGestureRecognizer ();
panGesture.PanUpdated += OnPanUpdated;
imageContainer.GestureRecognizers.Add (panGesture);
absoluteLayout = new AbsoluteLayout {
BackgroundColor = MyAppStyle.blackColor,
};
var label = new Label {
Text = DescriptionText,
TextColor = MyAppStyle.whiteColor,
FontAttributes = FontAttributes.Bold,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
};
var separator = new BoxView() { HeightRequest = 1, BackgroundColor = MyAppStyle.whiteColor};
imageDescription = new StackLayout {
Padding = new Thickness(20),
HorizontalOptions = LayoutOptions.Fill,
Orientation = StackOrientation.Vertical,
Children = { label, separator}
};
backButton = new Button { Text = "Back", WidthRequest = 80, HeightRequest = 40, TextColor = MyAppStyle.whiteColor, FontAttributes = FontAttributes.Bold };
backButton.Clicked += (object sender, EventArgs e) => { OnBackButtonPressed(); Navigation.PopAsync(); };
indexLabel = new Label {
Text = (index + 1).ToString () + " of " + count.ToString (),
TextColor = MyAppStyle.whiteColor,
FontAttributes = FontAttributes.Bold,
HorizontalTextAlignment = TextAlignment.Center
};
AbsoluteLayout.SetLayoutFlags (imageContainer, AbsoluteLayoutFlags.All);
AbsoluteLayout.SetLayoutBounds (imageContainer, new Rectangle (0f, 0f, 1f, 1f));
absoluteLayout.Children.Add (imageContainer);
AbsoluteLayout.SetLayoutFlags (imageDescription, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);
AbsoluteLayout.SetLayoutBounds (imageDescription, new Rectangle(0f, 1f, 1f, AbsoluteLayout.AutoSize));
absoluteLayout.Children.Add(imageDescription);
topBox = new BoxView { Color = MyAppStyle.blackColor, Opacity = 0.5 };
AbsoluteLayout.SetLayoutFlags (topBox, AbsoluteLayoutFlags.WidthProportional);
AbsoluteLayout.SetLayoutBounds (topBox, new Rectangle(0f, 0f, 1f, 50f));
absoluteLayout.Children.Add (topBox);
AbsoluteLayout.SetLayoutFlags (backButton, AbsoluteLayoutFlags.None);
AbsoluteLayout.SetLayoutBounds (backButton, new Rectangle(0f, 10f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
absoluteLayout.Children.Add (backButton);
AbsoluteLayout.SetLayoutFlags (indexLabel, AbsoluteLayoutFlags.XProportional);
AbsoluteLayout.SetLayoutBounds (indexLabel, new Rectangle(.5f, 20f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
absoluteLayout.Children.Add (indexLabel);
Content = absoluteLayout;
}
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height); //must be called
if (ScreenWidth != width || ScreenHeight != height) {
absoluteLayout.ForceLayout();
originalWidth = imageContainer.Content.Width / imageContainer.Content.Scale;
originalHeight = imageContainer.Content.Height / imageContainer.Content.Scale;
ScreenWidth = width;
ScreenHeight = height;
xOffset = imageContainer.Content.TranslationX;
yOffset = imageContainer.Content.TranslationY;
currentScale = imageContainer.Content.Scale;
}
}
void OnTapped(object sender, EventArgs e)
{
ShowEverything = !ShowEverything;
}
void OnPanUpdated (object sender, PanUpdatedEventArgs e)
{
var s = (ContentView)sender;
// do not allow pan if the image is in its intial size
if (currentScale == 1)
return;
switch (e.StatusType) {
case GestureStatus.Running:
double xTrans = xOffset + e.TotalX, yTrans = yOffset + e.TotalY;
// do not allow verical scorlling unless the image size is bigger than the screen
s.Content.TranslateTo (xTrans, yTrans, 0, Easing.Linear);
break;
case GestureStatus.Completed:
// Store the translation applied during the pan
xOffset = s.Content.TranslationX;
yOffset = s.Content.TranslationY;
// center the image if the width of the image is smaller than the screen width
if (originalWidth * currentScale < ScreenWidth && ScreenWidth > ScreenHeight)
xOffset = (ScreenWidth - originalWidth*currentScale)/2 - s.Content.X;
else
xOffset = Math.Max (Math.Min (0, xOffset), -Math.Abs (originalWidth * currentScale - ScreenWidth));
// center the image if the height of the image is smaller than the screen height
if (originalHeight * currentScale < ScreenHeight && ScreenHeight > ScreenWidth)
yOffset = (ScreenHeight - originalHeight*currentScale)/2 - s.Content.Y;
else
yOffset = Math.Max (Math.Min ((originalHeight - ScreenHeight)/2, yOffset), -Math.Abs(originalHeight*currentScale - ScreenHeight - (originalHeight - ScreenHeight)/2));
// bounce the image back to inside the bounds
s.Content.TranslateTo (xOffset, yOffset, 500, Easing.BounceOut);
break;
}
}
void OnPinchUpdated (object sender, PinchGestureUpdatedEventArgs e)
{
var s = (ContentView)sender;
if (e.Status == GestureStatus.Started) {
// Store the current scale factor applied to the wrapped user interface element,
// and zero the components for the center point of the translate transform.
startScale = s.Content.Scale;
s.Content.AnchorX = 0;
s.Content.AnchorY = 0;
}
if (e.Status == GestureStatus.Running) {
// Calculate the scale factor to be applied.
currentScale += (e.Scale - 1) * startScale;
currentScale = Math.Max (1, currentScale);
currentScale = Math.Min (currentScale, 5);
//scaleLabel.Text = "Scale: " + currentScale.ToString ();
if (currentScale == 1)
ShowEverything = true;
else
ShowEverything = false;
// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
// so get the X pixel coordinate.
double renderedX = s.Content.X + xOffset;
double deltaX = renderedX / ScreenWidth;
double deltaWidth = ScreenWidth / (s.Content.Width * startScale);
double originX = (e.ScaleOrigin.X - deltaX) * deltaWidth;
// The ScaleOrigin is in relative coordinates to the wrapped user interface element,
// so get the Y pixel coordinate.
double renderedY = s.Content.Y + yOffset;
double deltaY = renderedY / ScreenHeight;
double deltaHeight = ScreenHeight / (s.Content.Height * startScale);
double originY = (e.ScaleOrigin.Y - deltaY) * deltaHeight;
// Calculate the transformed element pixel coordinates.
double targetX = xOffset - (originX * s.Content.Width) * (currentScale - startScale);
double targetY = yOffset - (originY * s.Content.Height) * (currentScale - startScale);
// Apply translation based on the change in origin.
var transX = targetX.Clamp (-s.Content.Width * (currentScale - 1), 0);
var transY = targetY.Clamp (-s.Content.Height * (currentScale - 1), 0);
s.Content.TranslateTo (transX, transY, 0, Easing.Linear);
// Apply scale factor.
s.Content.Scale = currentScale;
}
if (e.Status == GestureStatus.Completed) {
// Store the translation applied during the pan
xOffset = s.Content.TranslationX;
yOffset = s.Content.TranslationY;
// center the image if the width of the image is smaller than the screen width
if (originalWidth * currentScale < ScreenWidth && ScreenWidth > ScreenHeight)
xOffset = (ScreenWidth - originalWidth*currentScale)/2 - s.Content.X;
else
xOffset = Math.Max (Math.Min (0, xOffset), -Math.Abs (originalWidth * currentScale - ScreenWidth));
// center the image if the height of the image is smaller than the screen height
if (originalHeight * currentScale < ScreenHeight && ScreenHeight > ScreenWidth)
yOffset = (ScreenHeight - originalHeight*currentScale)/2 - s.Content.Y;
else
yOffset = Math.Max (Math.Min ((originalHeight - ScreenHeight)/2, yOffset), -Math.Abs(originalHeight*currentScale - ScreenHeight - (originalHeight - ScreenHeight)/2));
// bounce the image back to inside the bounds
s.Content.TranslateTo (xOffset, yOffset, 500, Easing.BounceOut);
}
}
}
}
Hi there . I have a question . I'm learning android studio with java because about 90% of the companies in my country works with android studio . But i like the c# and visual studio . I work with visual studio for many years
My question is , can I learn xamarin and android studio together ? I want to know their codes of android are same ?is the only difference in syntax ?
Hello,
I am using a Tabbed Page for my main page and added icons for each content page. On Android those icons looks very nice, but same Icons on iOS looks awful.
For those icons, I am using png files. What types of image / icon types are you using and which can you recommend?
What does mean iOS Icons look awful?
Here is it in android:
You can see, icons are white and even other colors are displayed.
How it looks on iOS:
I am using xaml xml to specify the source of those icons.
<ContentPage x:Name="contentPage_ABC" BackgroundColor="White" Icon="MyIcon.png">
Thanks for all tipps !
Hi,
I just new on using XAMARIN on Visual Studio. I would like to ask on how to remove the titlebar on the activity_main.axml
Thanks.
Greetings everyone, I'm trying to display an Alert for my user but the function is not awaiting the Device.BeginInvokeOnMainThread to give the correct wannaChange, I've tryied somethings but didnt manage to get the correct answer , am I implementing the await/async wrong?
public async Task<bool> QuerSincronizarRelogio()
{
bool wannaChange = false;
Device.BeginInvokeOnMainThread(async () =>
{
try
{
var answer = await AirSenseApp.App.Current.MainPage.DisplayAlert("Sem conexão com internet", "Gostaria de prosseguir com Acesso Local?", "Sim", "Não");
if(answer)
{
Console.WriteLine("\n Wanna Change True \n ");
wannaChange = true;
}
else
{
Console.WriteLine("\n Wanna Change False \n ");
wannaChange = false;
}
}
catch(Exception ex)
{
Debug.WriteLine(ex);
}
});
Console.WriteLine("\n Return WannaChange {0} \n ",wannaChange);
return wannaChange;
}
I found a workaround but is really uggly, I think there is a cleaner way to solve this
public async Task<bool> QuerSincronizarRelogio()
{
bool wannaChange = false;
string wtf = "";
Device.BeginInvokeOnMainThread(async () =>
{
var answer = await AirSenseApp.App.Current.MainPage.DisplayAlert("Sem conexão com internet", "Gostaria de prosseguir com Acesso Local?", "Sim", "Não");
if(answer)
{
Console.WriteLine("\n Wanna Change True \n ");
wtf = "1";
wannaChange = true;
}
else
{
wtf = "1";
Console.WriteLine("\n Wanna Change False \n ");
wannaChange = false;
}
});
int aux = 1;
while(aux == 1)
{
if(wtf!="")
{
Console.WriteLine("\n While True {0} \n ", wtf);
aux = 0;
}
await Task.Delay(10);
}
Console.WriteLine("\n Return WannaChange {0} \n ", wannaChange);
return wannaChange;
}
Hello,
What is the most popular and mature video player library used in Xamarin.Forms nowadays? I am aware of Adam Fisher's Xamarin.Forms.VideoPlayer library but although it is pretty successful on iOS, the Android version is really incompetent; it can't even play videos full screen. I understand that this is the default Android video player but I am willing to use a custom video player if it is feature complete. Moreover the library seems to be abandoned since it's last bugfix was on April 23, 2018.
I need to play videos which are built-in to the application, preferably with minimal amount of configuration and custom renderers. It's OK if it's paid. Any ideas and tips?
I am running Visual Studio 15.9.5 on Windows 10, I have a MacBook Pro with Visual Studio for Mac and all the latest updates, with Xcode 10.1.
In Xcode Preferences/Components, you can see I have installed iOS 10.0 Simulator, 10.1,10.2,10.3.1,11.0,11.1,11.2, 11.3, 11.4, 12.0.
While paired up with the MacBook Pro, in DEBUG mode, I can see all the iPhone 5 and 6's from 10.3 to 12.1 (I am targeting 10.3).
However, in this list, there are no iPhone 7's or above. In the unsupported list, it does some some iPHone 7's, but they are older than 10.3.
Does anyone have some suggestions as to how I can fix this?
Hello everyone, I'm having a problem with TextView, I'm trying to leave it with a wave effect similar to the button, I tried to implement "android: clickable = 'true'", but it did not work ... anyone know of any efficient method?
My FirstView.axml
My FirstView.cs
using Android.App;
using Android.OS;
using MvvmCross.Droid.Views;
namespace EfeitoWave.Droid.Views
{
[Activity(Label = "View do Android")]
public class FirstView : MvxActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.FirstView);
}
}
}
Just as the title says, I've been developing with Xamarin for a few years, obviously have my MCSD App Builder certification etc. But would really like to see some Microsoft Certifications for Xamarin (MTA, MCSA, MCSD etc.).
Is this something that will be arriving soon, or something that might be in the pipeline?
The placeholder text looks 'right' on Android 6:
but on Android 4.4 it's black and a bit too strong
Is there a way to fix this app-wide without having to set a colour with an Alpha value for every entry?
My Xamarin.Forms app runs fine on emulators, and I can connect an iPhone 5 to my MacBook and successfully debug and run the app on a physical phone in debug mode. However, after pushing the release to "TestFlight", the app appears to start with the splash screen, then just disappears.
In my AppDelegate.cs in "FinishedLaunching", i wire up for unhandled exceptions like this:
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
Then, from within these handlers, I report crashes to my own backend log system, but also I have code to record the crash with App Center's "Crashes.TrackError()". I have verified this works by creating a test page that generates unhandled exceptions, and it successfully is caught with my error handlers and reported to the server.
When I run the app from TestFlight, the app crashes immediately, and no log information is sent to my log system, or to App Center. This is my nightmare scenario in support phones, crashes that I have no details about.
Can you please share any suggestions or ideas you may have, on how I can go about solving this crash problem; or how I can get diagnostics information from this crash, and future crashes.
Thanks.
Hey developers,
I have so far tried to use a carousel view due to its ease of use and of course its performance. But I tried to show the tail of each UI elements (let's say we've a bunch of cards) whatever the position is as shown in the picture. I've googled a lot and posted another question in this forum but since then I changed the project UI a little bit so I ignored the given solution and now I am on my own again, I resolved it (show the next card's tail or/and the previous), I'll write down the structure I used in XAML but first let me highlight my requirements.
I want to reproduce the behaviour, animation/transition on swiping of the carousel view to my view, because I am actually using a horizontal scroll view with a Flex layout inside.
Here is the structure :
Now I've tried two options :
1- Use of Scrolled event in the scroll view but that hasn't been a great option because it fire the events (animation or transition) after the scroll is done, in my case it should fire the event since scrolling started.
2- Use of SwipeGestureRecognizer on Scrollview, FlexLayout and BoxView : couldn't get a stable behaviour on the 2 first attempts but when I used a BoxView I couldn't get each StackLayout (the StackLayout is my card) inside the BoxView (It wasn't built for that).
Here is my UI after I used a horizontal scroll view :
here is the behaviour I wanted to reproduce to my view :
https://media.giphy.com/media/l0NwH3XDSYhQ6l4TC/giphy.gif
I have a simple picker inside a list view and on my devices when I use my finger to scroll or tap it pops up twice
I have verified this on multiple devices and I know it is not my code - it's just a picker
best
JK
However drag and drop in Xamarin forms just showed a red circle with a slash through it. Is this a paid feature that is required
to use which means upgrading from Visual Studio 2017 Community. I tried everything including
removing anti-virus and reinstalling. Was a major headache after getting everything setup. So is this
a paid feature if so I have already invested time on other platforms but would still like to know.
Hello everyone
My problem is about installing nuget Xamarin.Essentials package for Android.
To isolate the error I started a new empty Xamarin project that I called "test".
I am installing this package directly from Visual Studio and I have the error:
**All packages are compatible with MonoAndroid, Version = v8.1.
Package restore failed. Rolling back package changes for 'test.Android'.
**
I did not find a solution to my problem on the internet.
Can someone help me and tell me where this error comes from and how to solve it.
Thank you for your answers
YC
Hello everyone
I develop currently a application Xamarin.Android and i would like to use material components (MDC) material.io, in my application because i like the design in contrary to the basic design of Xamarin.Android. do you have an idea to create binding java library for MDC please ?
PS : i already watch the tutorial a binding java
Hello developers,
I'm using the plugin https://github.com/CrossGeeks/FirebasePushNotificationPlugin and https://github.com/winstongubantes/MatchaBackgroundService
The plugin work good, I receive the push notification with background, Foreground and too when the app is closed.
The problem is that plugin FirebasePushNotification, with event OnNotificationReceived detect the event when app is background but don't enters the event, without de event OnNotificationReceived, all it works good! when I receive the push notifacion with mi app the background and I have other code, for example show alert and back the app foreground it works!, the alert it's visible.
I need the following:
My app don't' use commercial, only professional.
When receive push notification and my app is foreground, show alert (it works), when my background app receive push notification with de plugin, show alert (when back foreground app).
Any examples?
Where find information?
Thanks advance.
I have
Project 1 Default for the other platforms
Folder
Project 2 Android
Folder
Project 3 iOS
Folder
PART 1
If i want to count the number of items in the Images folder
how do i do it?
Can i do it in the default, with embedded images
or do i need to do it with platform specific logic. if so how.
numbers of items: 2
PART 2
And when i can count the numbers of items in the folder, and how can i take out there names.
names
List list = new List();
foreach() {
list.add(x); // 1.jpg 2.jpg
}
I want to process the data in a database before any UI pulls the data from it through View Model. Since async / await operations involved, which is the best place to pre-process data?
I find doing it in OnAppearing() is not meeting my requirement and I have to pull to refresh the ListView.