What is the best way to implement the Sliding up Panel used in apps like Google Maps in Xamarin.Forms?
Sliding up Panel in Xamarin.Forms?
Data is not getting binded to the listview using web api in xamarin forms cross platform
Hello Sir,
I'm trying to display the data from database based on dropdown selection in xamarin forms cross platform
below is the code I'm using, but here nothing is getting displayed. please help me
Thanks
page3.xaml.cs
Rostercs roles = new Rostercs();
roles.staff_name = role.SelectedItem.ToString();
string url = "http://********/api/StaffRoster/details";
HttpClient client = new HttpClient();
string JsonData = JsonConvert.SerializeObject(roles);
StringContent content = new StringContent(JsonData, Encoding.UTF8, "application/json");
var response = await client.PostAsync(url,content);
string result = await response.Content.ReadAsStringAsync();
var details = JsonConvert.DeserializeObject<List>(result);
Models1.ItemsSource = details;
////web api
public IEnumerable details( Rostercs name )
{
List staffroster = new List();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from test where rowstate=1 and staff_name='"+name.staff_name+"' order by date asc";
cmd.Connection = con;
con.Open();
SqlDataReader staff_roster = cmd.ExecuteReader();
while (staff_roster.Read())
{
Rostercs roster = new Rostercs();
roster.staff_name = staff_roster["staff_name"].ToString();
roster.day = staff_roster["day"].ToString(); staffroster.Add(roster); } con.Close(); return staffroster; }
How to change the webview resolution?
I created a webpage for an indoor map application which use javascript canvas 2D for rendering. I manage to display the website in mobile phone using webview however the font size and line width in webview is bigger than in chrome browser. I check the resolution in mobile chrome browser it return me width 980, height 1524 but in xamarin webview it return me width 360, height 584. Anyone know how to set the webview screen to higher resolution? Thanks in Advance!
Cannot get SerialPortInfo through Intent Xamarin Forms
Hello guys!
I am extremely new to Xamarin Forms.
I am trying to connect to Serial Port through Android OS & I am using Xamarin Forms.
I found a project on BitBucket which uses a specific dll to communicate with the Serial Port. I have attached the project for you reference. The dll can be found in the debug folder of the same.
The sample project works flawlessly. However, since it was just an activity and had no UI, I had to create my own project with buttons to open and close the connection with the Serial Port.
I copied all the code from the sample project and added it to my app. However, the following line causes an error due to which I am not able to compile :
portInfo = Intent.GetParcelableExtra(EXTRA_TAG) as UsbSerialPortInfo;
This is the error - "An object reference is required for the non static field method or property Intent".
How can I resolve this error?
Thank You!
icon and text color in a swipeview
I have been struggling for few hours to get the icon correct in a swipeview.
I tried to show an icon in a swipeview using embedded resources but I could not get through as it is very complicated:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#embedded-images
So I try to show a local image:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images
The delete.png is in the Android project folder/Resources/drawable/
The image is that one:
The code is that one:
<ListView.ItemTemplate> <DataTemplate> <ViewCell> <SwipeView BackgroundColor="{StaticResource AppBackgroundColor}" Margin="2"> <!-- <StackLayout Orientation="Horizontal" HorizontalOptions="Start"></StackLayout> --> <SwipeView.LeftItems> <SwipeItems Mode="Execute"> <SwipeItem Text="{i18n:Translate buttonDelete}" IconImageSource="delete.png" BackgroundColor="{StaticResource TextRedNightColor}" StyleClass="" Invoked="OnDeleteSight"/> </SwipeItems> </SwipeView.LeftItems> <!-- </StackLayout> --> <Frame CornerRadius="16" Margin="0" BackgroundColor="{StaticResource CellDefaultColor}" HasShadow="False" BorderColor="{StaticResource CellDefaultColor}" > <StackLayout Orientation="Vertical" Margin="1" Padding="0" BackgroundColor="{StaticResource CellDefaultColor}">
The result is there:
- How can I get a black drawing on the SwipeItem BackgroundColor?
- Is it possible to have the icon and text on the left and not centered? I guess I have to create a custom item...
Xamarin Forms app with cloud hosting - possible NOSQL Database and user authentication (signin etc)?
Hi all,
Feeling abit lost here but question regarding implementing a backend server side cloud storage & user authentication for signup/login etc. etc for an Xamarin.Forms app...
I have basically developed an app in Xamarin forms which is just ready to hook up to endpoints server side for user creation and cloud storage but Im struggling to go about this the best way. Ideally i wont be running my own local web application with a SQL database, rather I could have a NOSQL database in the cloud that can scale well and let the cloud handle all authentication plus user creation etc. This way I can focus more on the app side of things.
There might be other (better) options but so far I have looked into Azure and was able to setup Azure AD B2C in which I could test run it and seemed to work although does it only support webviews? Ideally I would style up my own login/signup page that take input and send that off to some endpoint. I was also looking into cosmos db which would be ideal for data storage but how does it work with user setup and authenticate in Azure AD B2C? Does it work this way?
On the other hand firebase might be a good option Real-time Database, Storage, Notifications, Authentication, and Hosting all of which I require.
Lastly does cloud hosting remove the need for a web application that I need to deploy to the cloud? Im assuming I still need to setup some web application that I deploy to the cloud that provides and API interface for the client side and inturn the web application would talk with the cloud as a type of middle ware software?
Not necessarily looking for complete code samples but just some direction or other peoples experience around setting up server side cloud authentication data storage with a Forms application
Getting error as “specified cast is not valid” in Xamarin forms cross platform
Im trying to bind the data from the database to the listview in Xamarin forms based on the if else condition , using below code I'm getting an error for "Specified cast is not valid",also rather than returning the value as B i want tobind the result from the database please help me
public class Class1: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var date = (DateTime)value;
DateTime dResult = DateTime.ParseExact("00:00:00.0000000", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
if (date == dResult)
return "";
return "B";
} public object Convert1(object value, Type targetType, object parameter, CultureInfo culture) { var date = (DateTime)value; DateTime dResult = DateTime.ParseExact("00:00:00.0000000", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); if (date == dResult) return ""; return "B"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }
}
Thanks in advance
[Android] App Crashing while Page Navigation with error as NavigationPageRenderer.UpdateToolbar ()
When I am trying to move from one page to another page, the app is getting crashed with the below error. This is happening after I upgraded the Xamarin.Forms version to 4.7.0.1080
NavigationPageRenderer.UpdateToolbar () - System.NullReferenceException: Object reference not set to an instance of an object.
Xamarin Forms Version: 4.7.0.1080
Note:
- Sometime App not crashing but BackButton Icon & Header Label not showing.
- Is there any possibility to resolve this issue by downgrading the Xamarin.Forms version to 4.6 or 4.5.
AppCenter Stack Trace:
Android: 9
Android Build: PKQ1.180917.001
Manufacturer: Xiaomi
Model: Redmi 6 Pro
Xamarin Exception Stack:
System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.UpdateToolbar () [0x0007d] in <5cfeb6476b5641c5b43daf7d3f36a1c8>:0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer+<>c__DisplayClass97_0.b__0 () [0x0002b] in <5cfeb6476b5641c5b43daf7d3f36a1c8>:0
at Xamarin.Forms.Forms+AndroidPlatformServices+<>c__DisplayClass24_0.b__0 () [0x00000] in <5cfeb6476b5641c5b43daf7d3f36a1c8>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in :0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in :0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.28(intptr,intptr)
How do I ensure that the view model and the page loads before a custom control?
I need to set values in a custom control created in a Xamarin.Forms Project from the view model created within the same project.
How do I ensure that the view model and the page loads before the custom control?
Is this possible?
The TitleView is not full since the safeArea in Xamarin.Forms.Shell.
I created a CustomView and want to put it in TitleView.<Shell.TitleView> <local:TitleView></local:TitleView> </Shell.TitleView>
how to make it fill the tilteview?
Open Popup (Rg.Plugin.Popup) with parameter MVVM.
Hello. Please submit ideas how ican send and receive data in the ViewModel when opening?
At the moment, I opened a popup without parameters, but I don't even have any ideas on how to open a popup with parameters.
public async Task<object> ShowDialogAsync(PopupPage popupPage, bool animate = true) { var getViewModel = popupPage.BindingContext as ViewModelBase; TaskCompletionSource<object> tcs = new TaskCompletionSource<object>(); MessagingCenter.Subscribe<ViewModelBase, object>(getViewModel, MessageKeys.DialogResult, (sender, resultObject) => { tcs.TrySetResult(resultObject); }); await PopupNavigation.Instance.PushAsync(popupPage, animate); var returnObject = await tcs.Task; await CloseLastDialogAsync(); return returnObject; }
Command Binding in ViewModel working in emulator but not working in real device of android 7.1
Hello i am a beginner in Xamarin. i have been trying to implement Command Binding using viewmodel in xamarin forms application.
i have been using the nuget package called Refactored.mvvmhelpers by montemagno. its working perfectly in emulator ( Android 7.1 api 25) but whenever i am building .apk file by visual studio 2017 and trying to install it on my real device Xaomi MI MAX 2 ( Android 7.1 api 25) . The Click event is not firing in the real device. And also The Page title is not showing which is binded to the Title property of ViewModel.
Any help would be highly appreciated.
please see the attached file for the codes
Thanks
How to go to SPECIFIC PAGE when user clicks on Push Notification
I have a Xamarin.Forms app (XF 1.3.4) that uses Azure Messaging to connect with GCM and APNS. The app works great - the app registers for push notifications, and push notifications are received successfully from Azure Notification Hubs on iOS and Android.
My question - how do I get my app to launch into or display a specific page when the user taps on a push notification, (1) when the app isn't running, AND (2) when the app is already running???
I've seen this question asked a few times in the forums, but I haven't seen a cohesive/detailed response yet.
Can someone please provide an answer with source code, or point me to a solution online that explicitly shows how to pass data from a push notification, through the platform-specific code, to the PCL code? ALSO, I don't want or need to integrate with another plugin (Push Notifications Plugin or otherwise) - I have push notifications working, I just need to make them content-aware.
Thanks!
ListView not displaying text
Hi,
In my page list view content is not displayed, but click event is working, below is the code
<ListView BindingContext="Menu_items" RowHeight="60" x:Name="li_menu" ItemSelected="li_menu_ItemTapped"> <ListView.ItemTemplate > <DataTemplate> <ViewCell > <ViewCell.View> <StackLayout Orientation="Horizontal" Margin="10,10,10,10" VerticalOptions="Center"> <Frame CornerRadius="30" HeightRequest="40" WidthRequest="40" HorizontalOptions="Center" VerticalOptions="Center" Padding="0" IsClippedToBounds="True"> <Image Source="{Binding ImageUrl}" HorizontalOptions="Center" VerticalOptions="Center" HeightRequest="40" WidthRequest="40"/> </Frame> <Label Text="{Binding Name}" VerticalTextAlignment="Center" FontSize="14" FontAttributes="Bold"/> <Label VerticalTextAlignment="Center" Margin="10" HorizontalOptions="EndAndExpand" /> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackLayout>
// Code
List Menu_items = new List();
int cnt = doc.GetElementsByTagName("id").Count;
for (int i = 0; i < cnt; i++)
{
Menu_items.Add(new MenuItems
{
Name =CheckXMLNode(doc.GetElementsByTagName("menu_name")[i]),
Id = CheckXMLNode(doc.GetElementsByTagName("id")[i]),
ImageUrl = App.api_url + "/menuicon/" + CheckXMLNode(doc.GetElementsByTagName("id")[i]).Remove(0, 1) + ".png",
New = CheckXMLNode(doc.GetElementsByTagName("display_count")[i]),
PageName = CheckXMLNode(doc.GetElementsByTagName("page_name")[i])
});
}
li_menu.ItemsSource = Menu_items;
BindingContext = this;
li_menu.HasUnevenRows = true;
Call Http and Https WCF service request from Xamarin.Forms
Hi,
Xamarin.Forms
I have created one application in Xamarin.Forms.
I can able to request WCF service with HTTP protocol and get the response. But I was not able to request wcf service with HTTPS protocol and we got an error "There was no endpoint listening at {0} that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.".
I am using below snippet in my application.
HTTP request snippet:
var binding = new BasicHttpBinding()
{
Name = "basicHttpBinding",
MaxReceivedMessageSize = 67108864,
};
var timeout = new TimeSpan(0, 1, 0); binding.SendTimeout = timeout; binding.OpenTimeout = timeout; binding.ReceiveTimeout = timeout; MobileOperationClient client = new MobileOperationClient(binding, new EndpointAddress("https://{Url}/MobileOperation.svc"));
HTTPS request snippet:
var binding = new BasicHttpBinding()
{
Name = "basicHttpBinding",
MaxReceivedMessageSize = 67108864,
};
var timeout = new TimeSpan(0, 1, 0); binding.SendTimeout = timeout; binding.OpenTimeout = timeout; binding.ReceiveTimeout = timeout; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; MobileOperationClient client = new MobileOperationClient(binding, new EndpointAddress("https://{Url}/MobileOperation.svc"));
How can I make it work both http and https WCF service request from Xamarin.Forms?
Thanks,
Could not resolve type with token 01000012
I've been developing my app now for at least 5 months. I've been wanting to try the xamarin previewer so i updates visual studio xamarin forms and then i updated my nuget xamarin forms for my portable, ios and android.
now when i try to debug the application on the device i get
System.TypeLoadException: Could not resolve type with token 01000012
on this line
global::Xamarin.Forms.Forms.Init(this, bundle);
which i find very odd
origionally my xamarin forms nuget version was 2.3.3.168
so i thought id update to the stable version which was the same version number 2.3.3.168 but it had "stable" beside it
i've downgraded again but still get the same error.
any thoughts
thanks
SQLite database missing in debug after device disconnected and reconnected to USB
Hello,
may be somebody can shed the light how to solve the following problem:
I am writing app with xamarin forms using SQLite for storing local data.
at some point I found, that sometimes my SQLite database missing . couple of days I was searching through internet trying to find the solution and checking everything ..
today I found, that it happens after I disconnect device from USB, connect it back and trying to start debugging
configuration.
windows 10 pc (10.0.17134.407), MS VS 15.9.2, Xamarin Forms 3.4.0.1008975 , SQLite-net-pcl 1.5.231 . device Samsung S7edge (SM-G935FD) with android 8.0.0
piece of code
if (!File.Exists(dbfname)) { System.Diagnostics.Debug.WriteLine("no database found, creating new"); IsNewDB = true; } else { IsNewDB = false; }
working as expected on a device during numerous debug session restarts, working on simulator, working on a device disconnected from computer. but once I connect it to computer and starts debugging session file.exists returns false
database is here dbfname = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "dbname.db"
thanks in advance
ish
Android Camera WebView Image Upload ERR_FILE_NOT_FOUND
I am working on a simple app that views a webpage that has an area for a user to take pictures and upload them to the site.
I found some examples that look like this
public class CustomWebViewRenderer : WebViewRenderer { Activity mContext; private static int FILECHOOSER_RESULTCODE = 1; public CustomWebViewRenderer(Context context) : base(context) { mContext = context as Activity; } protected override void OnElementChanged(ElementChangedEventArgs<WebView> e) { try { base.OnElementChanged(e); var chromeClient = new FileChooserWebChromeClient((uploadMsg, acceptType, capture) => { MainActivity.UploadMessage = uploadMsg; // Create MyAppFolder at SD card for saving our images File imageStorageDir = new File(Android.OS.Environment.GetExternalStoragePublicDirectory( Android.OS.Environment.DirectoryPictures), "MyAppFolder"); if (!imageStorageDir.Exists()) { imageStorageDir.Mkdirs(); } // Create camera captured image file path and name, add ticks to make it unique var file = new File(imageStorageDir + File.Separator + "IMG_" + DateTime.Now.Ticks + ".jpg"); MainActivity.mCapturedImageURI = Android.Net.Uri.FromFile(file); // Create camera capture image intent and add it to the chooser var captureIntent = new Intent(MediaStore.ActionImageCapture); captureIntent.PutExtra(MediaStore.ExtraOutput, MainActivity.mCapturedImageURI); var i = new Intent(Intent.ActionGetContent); i.AddCategory(Intent.CategoryOpenable); i.SetType("image/*"); var chooserIntent = Intent.CreateChooser(i, "Choose image"); chooserIntent.PutExtra(Intent.ExtraInitialIntents, new Intent[] { captureIntent }); (mContext).StartActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE); }); Control.SetWebChromeClient(chromeClient); } catch (Exception ex) { var j = ex; } } } public class FileChooserWebChromeClient : WebChromeClient { private Action<IValueCallback, Java.Lang.String, Java.Lang.String> callback; public FileChooserWebChromeClient(Action<IValueCallback, Java.Lang.String, Java.Lang.String> callBack) { callback = callBack; } // For Android < 5.0 [Java.Interop.Export] public void openFileChooser(IValueCallback uploadMsg, Java.Lang.String acceptType, Java.Lang.String capture) { callback(uploadMsg, acceptType, capture); } // For Android > 5.0 public override Boolean OnShowFileChooser(Android.Webkit.WebView webView, IValueCallback uploadMsg, WebChromeClient.FileChooserParams fileChooserParams) { try { callback(uploadMsg, null, null); } catch (Exception ex) { var j = ex; } return true; } }
Added this to the MainActivity
public static Android.Webkit.IValueCallback UploadMessage; private static int FILECHOOSER_RESULTCODE = 1; public static Android.Net.Uri mCapturedImageURI; protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == UploadMessage) return; Java.Lang.Object result; if (data != null && data.Data != null) result = data.Data; else result = mCapturedImageURI; UploadMessage.OnReceiveValue(new Android.Net.Uri[] { (Android.Net.Uri)result }); UploadMessage = null; } else base.OnActivityResult(requestCode, resultCode, data); }
This works fine on older versions of Android but when I loaded it up on Android 8, I get the message "ERR_FILE_NOT_FOUND" from the website.
I feel like I'm close, but missing something small to make this work.
Button event not firing in Grid for iOS but working fine on Android.
Button event not firing in Grid for iOS but working fine on Android. If I put button in the stack layout it works.
` <Grid HeightRequest="40"> <Grid.ColumnDefinitions> <ColumnDefinition Width="5*" /> <ColumnDefinition Width="5*" /> </Grid.ColumnDefinitions> <sfButton:SfButton x:Name="Gallery" IsEnabled="{Binding IsSaveButtonEnabled}" IsVisible="{Binding SaveButton}" Grid.Column="0" CornerRadius="5" HorizontalOptions="Fill" Command="{Binding SaveExpenseCommand}" Text="Save"> <sfButton:SfButton.BackgroundGradient> <gradient:SfLinearGradientBrush> <gradient:SfLinearGradientBrush.GradientStops> <gradient:SfGradientStop Color="#2F9BDF" Offset="0" /> <gradient:SfGradientStop Color="#51F1F2" Offset="1" /> </gradient:SfLinearGradientBrush.GradientStops> </gradient:SfLinearGradientBrush> </sfButton:SfButton.BackgroundGradient> </sfButton:SfButton> <sfButton:SfButton x:Name="Camera" IsEnabled="{Binding IsSubmitButtonEnabled}" IsVisible="{Binding SaveButton}" Grid.Column="1" CornerRadius="5" HorizontalOptions="Fill" Command="{Binding SubmitExpenseCommand}" Text="Submit"> <sfButton:SfButton.BackgroundGradient> <gradient:SfLinearGradientBrush> <gradient:SfLinearGradientBrush.GradientStops> <gradient:SfGradientStop Color="#FFB57B" Offset="0" /> <gradient:SfGradientStop Color="#FF5361" Offset="1" /> </gradient:SfLinearGradientBrush.GradientStops> </gradient:SfLinearGradientBrush> </sfButton:SfButton.BackgroundGradient> </sfButton:SfButton> <ActivityIndicator Grid.Column="0" Grid.ColumnSpan="2" IsRunning="{Binding IsLoading}" /> </Grid>`
Is there a limit in the number of converters to add as resources on a ContentPage?
Hi,
On Visual Studio Community Edition 8.6.5. I have 7 converters declared in the same namespace, each in a different class file. However, nothing beyond the 5th is showing under the identifier I declared for the name space
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:local="clr-namespace:STicket.Utilities" mc:Ignorable="d" x:Class="STicket.Views.CustomerPage" NavigationPage.HasBackButton="False"> <ContentPage.Resources> <local:StringCaseConverter x:Key="StringCaseConverterKey"></local:StringCaseConverter> <local:StringToBoolConverter x:Key="StringToBoolConverterKey"></local:StringToBoolConverter> <local:PositiveValueConverter x:Key="PositiveValueConverterKey"></local:PositiveValueConverter> <local:ReadyToPostConverter x:Key="ReadyToPostConverterKey"></local:ReadyToPostConverter> <local:StringToColorConverter x:Key="StringToColorConverterKey"></local:StringToColorConverter> </ContentPage.Resources>
''
Do I have too many converters or is this a Mac issue?
PS: I apologize, I do not remember how to format the code.