I am using Visual Studio For Mac. My Xamarin Forms project is quite large and contains many content pages. Some of them will be only used in android project and some of them only used in iOS project. There is no problem when I compile the project into android. However, when I want to compile the project into iOS, it seems like did not accept anything related to android. Please refer to the screenshot. There is no way I can include the android specialised reference and compile into iOS project. So, any idea to deal with this? Maybe there is a way to force build the iOS project no matter what? The error from the screenshot is from the page that will be only used in android. So what I can do for now is delete the page when I want to compile as iOS and recreate the page when I want to used it for android. But there are plenty of them, it is too heavy for me to do this every time. Please help.
How to include Android.Support.v4 in Xamarin Forms (iOS)?
Can I persist data in a lambda expression.
Hey there everyone.
I am trying to build a list of clickable tokens dynamically in my code.
My code is supposes to iterate through the list of retailers, and build a list of them 3 wide.
If the retailer has a URL entered, I am trying to do some basic validation for the data, then bind the URL to the Click event.
Likewise if there is no URL I want the Click event to link to the Retailers page so data can be modified.
The problem I have, is that the iterator is not persisting, so every single element has the last value of the iterator in it. IE, if there are 13 elements in the list, element 3, the iterator equals 13, instead of 3
Here's the code I am using...
XAML Code
<border:SfBorder x:Name="borderRetailers" VerticalOptions="FillAndExpand"> <StackLayout Margin="2" Orientation="Vertical"> <Label Style="{StaticResource Key=BorderLabel}" Text="Retailers" /> <StackLayout x:Name="slRetailers" HorizontalOptions="StartAndExpand" Orientation="Vertical" VerticalOptions="StartAndExpand" /> </StackLayout> </border:SfBorder>
XAML.CS Code
//Build the dynamic list of retailers. if (slRetailers.Children.Count != viewModel.RetailersList.Count) { slRetailers?.Children?.Clear(); var retailernum = 0; var AdjustedRetailCount = (viewModel.RetailersList?.Count - 1); const int chipsPerRow = 3; if (viewModel.RetailersList?.Count > 0) { while (retailernum <= AdjustedRetailCount) { var chipCount = 0; //Create a new instance pf a stack layout var slgroup = new StackLayout { Orientation = StackOrientation.Horizontal, VerticalOptions = LayoutOptions.StartAndExpand, Spacing = 1, }; while (chipCount < chipsPerRow && retailernum <= AdjustedRetailCount) { var szName = viewModel.RetailersList[retailernum]?.Name; if (!string.IsNullOrEmpty(szName)) { var cpRetailer = new SfChip { Text = szName }; if (viewModel.RetailersList[retailernum].URL.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || viewModel.RetailersList[retailernum].URL.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { cpRetailer.Clicked += async (s, e) => await Launcher.OpenAsync(new Uri(viewModel.RetailersList[retailernum].URL)).ConfigureAwait(true); } else { //Ugly and extremely problematic validation, I need to regex this in the future or something. if (viewModel.RetailersList[retailernum].URL.Contains(".com") || viewModel.RetailersList[retailernum].URL.Contains(".net") || viewModel.RetailersList[retailernum].URL.Contains(".org") || viewModel.RetailersList[retailernum].URL.Contains("www.")) { cpRetailer.Clicked += async (s, e) => await Launcher.OpenAsync(new Uri("http://" + viewModel.RetailersList[retailernum].URL)).ConfigureAwait(true); } else { cpRetailer.Clicked += async (s, e) => await Navigation.PushAsync(new AddRetailer(new RetailerViewModel(viewModel.RetailersList[retailernum].Id))).ConfigureAwait(true); } } slgroup.Children.Add(cpRetailer); chipCount++; retailernum++; } else { chipCount++; retailernum++; break; } } slRetailers.Children.Add(slgroup); } } }
Any help is much appreciated!
Cheers!
How to connect ASP.NET Core 3.0 Web Api (https/http) in Xamarin.Forms apps.
Hi Friends,
I am new in Xamarin.Forms.
Last two days I am trying to connect Xamarin.Forms application with Web Api. But I can't access the APi from Xamarin.
The Xamarin.Forms consumes Android and IOS application.
Tools and Versions Using
Visual Studio 2019 Community
Xamarin.Forms v 4.4.0
Web APi - ASP.NET Core 3.0 Web APi
The web Api is working perfectly.(Checked with POST MAN app).
Following code I am used in the Xamarin form to connect API.
using (HttpClient httpClient = new HttpClient()) { //httpClient.BaseAddress = new Uri("https://localhost:44393/"); //https://10.0.2.2:5001/Api/Home/AddPost //var content = new StringContent(JsonConvert.SerializeObject(post)); var json = JsonConvert.SerializeObject(post); HttpContent httpContent = new StringContent(json); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await httpClient.PostAsync("https://localhost:5001/api/Home/AddPost", httpContent); result = await response.Content.ReadAsStringAsync(); }
The above code throw an error, Failed to connect to localhost/127.0.0.1:5001
The Web Api is in another solution and I am open and run in another instance of VS 2019 in same system.
Is there have any settings that have to add in Xamarin App?.
Please help me out.
Manu Mohan
Different Title Views in Tabbed Page
I have tabbed page in my application and i want to show different title for the each page in the navigation.titleviews. How can achieve this?
Xamarin forms : Event Handler with correct signature not found in Type ,
After updating to xamarin forms 4.4 we are facing this issue, Updated from xamarin forms forms 3.0 to 4.4 , Any suggestion?
upload Json with File to WepAPI
hi ,
how can i upload a file WITH json data to webAPI ?
i have sample of uploading file only , can i do both ?
for example i need to upload a file with some data added by user for that file , like this:
var content = new MultipartFormDataContent();
content.Add(new StringContent(JsonConvert.SerializeObject(new ChatRequest() { ContactId="Ass323f"})
, Encoding.UTF8, "application/json"));
content.Add(new StreamContent(filedata.GetStream()), "Thefile", fileName); var httpResponseMessage = await httpClient.PostAsync( $"{AppManager.ServerURL}chats/UploadAttachmentToServer", content);
but i always get
StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1,
server api code
[HttpPost(nameof(UploadAttachmentToServer))]
public IActionResult UploadAttachmentToServer(ChatRequest cr, IFormFile Thefile)
{
return Ok(new UploadAttachmentToServerResault()); }
How to get back to app after google login
Hi Everyone,
I'm trying to implement google login in my app using xamarin.auth like below
var auth = new OAuth2Authenticator("284202576320-7kgdhaa5sgvkoe03jmmcv0p8lfdma306.apps.googleusercontent.com","cAZW7uegD-h2- tNMMf5q1UGQ","https://www.googleapis.com/auth/userinfo.email",new Uri("https://accounts.google.com/o/oauth2/auth"),new Uri("http://dev.myfav.restaurant/Account/LoginComplete"),new Uri("https://accounts.google.com/o/oauth2/token"),null,true) { AllowCancel = true, };
but Completed event not firing and its going to web page after login i need to get back user to my app how can i achieve this ???? Can anyone help me on this please.
Thanks in advance
Using SkiaSharp, how to save a SKBitmap ?
After editing a SKBitmap in Xamarin.Forms i wanna save it in local storage.
Any idea?
Change TabbedPage Item FontSize on Android
Hello,
I added a TabbedPage with position bottom in my xamarin forms project.
On Android, the font size is too big.
I'm looking for a way to reduce the font size.
I'm also trying to remove the effect that makes the selected menu item bigger.
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:views="clr-namespace:namespace.Views" xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" xmlns:i18n="clr-namespace:namespace.Utils;assembly=namespace" Title="{Binding Title}" android:TabbedPage.ToolbarPlacement="Bottom" android:TabbedPage.BarItemColor="#002244" android:TabbedPage.BarBackgroundColor="White" android:TabbedPage.BarSelectedItemColor="#096cd0" x:Class="namespace.Views.MainPage"> <TabbedPage.Children> <NavigationPage x:Name="Home" Title="{i18n:Translate Menu_Home}" IconImageSource="accueil.png"> <x:Arguments> <views:Home /> </x:Arguments> </NavigationPage> <NavigationPage x:Name="Services" Title="{i18n:Translate Menu_MyServices}" IconImageSource="services.png"> <x:Arguments> <views:MyServices /> </x:Arguments> </NavigationPage> <NavigationPage x:Name="Documentation" Title="{i18n:Translate Menu_Documentation}" IconImageSource="documentation.png"> <x:Arguments> <views:Documentation /> </x:Arguments> </NavigationPage> <NavigationPage x:Name="VideoCall" Title="{i18n:Translate Menu_Video}" IconImageSource="videoconferenc.png"> <x:Arguments> <views:VideoCall /> </x:Arguments> </NavigationPage> </TabbedPage.Children> </TabbedPage>
Here is the result
We're finding that the "videoconsultation" doesn't have enough room.
It's even worse here
The word "services" disappears when selected.
I've done a lot of research, but I've found a way to make it work
When the menu is positioned at the top, I can change some settings in style.xml, but it doesn't seem to work when it's positioned at the bottom.
Do you have a solution?
Thank you very much,
Chris
Native classes without Custom Renderer
Is there a way to use Android and IOS native classes (Views like Android.Button, IOS.UIButton ecc...) in Xamarin Forms without creating a Custom Renderer?
How to add DisplayAlert in .NET Core Class Library
Hi,
I am trying to create a nuget package.
I create a new project .NET Core Class Library
Now I want to use the DisplayAlert i the class?
I am trying to use it but getting:
The type or namespace name 'DisplayAlert' could not be found (are you missing a using directive or an assembly reference?)
here is the code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using Xamarin.Essentials; using Xamarin.Forms; namespace MyClass { public class Loggeer { public void Log(string text) { DisplayAlert('test', 'test', 'test'); } } }
Xamarin Forms and WPF
I want to develop an application that has both a Xamrin Forms mobile component and a WPF component. I was considering putting the ViewModels in the shared, .Net Standard project, so I could use the VM's in both.
But in Xamarin.Forms, navigating from one view to another requires the use of the INavigation interface:await Navigation.PushAsync(new MyPage())
This interface doesn't exist in WPF.
I'm very new to Xamarin Forms. I would like to share VMs if I can. I'm open to hearing how this should work.
CollectionView swipe an item off screen to delete
Can anyone think of a way to make it so that a user can swipe an item in a CollectionView off the screen and have it removed from the CollectionView. AFAIK, A SwipeView won't work because it only uncovers actions to be chosen.
I thought maybe putting each item in a CarouselView with blank views on either side and removing the item from the CollectionView when the CarouselView's CurrentItem or Position changes.
Connect to Arduino (via USB Adapter or Bluetooth Adapter) with Xamarin Forms
Hi, I'm new to developing apps with Xamarin.
My goal is to write an App that can connect to an Arduino MiniPro. I have the needed hardware (connecting over USB or Bluetooth). First I programmed a Windows Forms program, but now I also need to use it on my Android Phone. So I need the App working on Windows (UWP) and Android. Is there any simple Example how to do this?
The most examples I found are just for Android - not for UWP.
Any help / example project would be very appreciated.
Thanks in advance,
Andreas
Control the output of app
hi
On exit or back button in app
Ask if you want to leave
Exit with confirmation
Otherwise stay
Prism DialogService extension method fails
This extension method is taken right from the Prism page, https://prismlibrary.com/docs/xamarin-forms/dialogs/dialog-service.html however, it looks like the code keeps calling the Callback function before the close is executed. When the same code is outside of the Task.Factory.SetNew the callback function is only executed after the dialog is closed. What is wrong with the extension method below?
public static Task ConfirmAsync(this IDialogService dialogService, string message)
{
var tcs = new TaskCompletionSource();
Task.Factory.StartNew(() => {
var parameters = new DialogParameters
{
{ "title", "Question" },
{ "message", message }
};
void Callback(IDialogResult result)
{
tcs.SetResult(result.Parameters.GetValue("confirmed"));
}
dialogService.ShowDialog("ConfirmationDialog", parameters, Callback);
});
return tcs.Task;
}
Is there a way to disable the sticky headers of a grouped ListView? (iOS)
Hello!
I've been trying to do this with Custom renderers but it seems to me that this may not be possible. Does anyone know some information about this?
I have tried with different approaches like:
https://stackoverflow.com/questions/1074006/is-it-possible-to-disable-floating-headers-in-uitableview-with-uitableviewstylep
https://stackoverflow.com/questions/664781/change-default-scrolling-behavior-of-uitableview-section-header/3984585#3984585
https://stackoverflow.com/questions/19056428/how-to-hide-first-section-header-in-uitableview-grouped-style
But without ant luck, any comment on this would be appreciate it.
Unable to connect a bluetooth.
Hi Everyone,
I am trying to accessing the bluetooth devices around the device with below code-->
async void btnScan_Clicked(System.Object sender, System.EventArgs e) { deviceList.Clear(); adapter.DeviceDiscovered += (s, a) => { if (deviceList.Contains(a.Device)) return; else deviceList.Add(a.Device); }; if (!ble.Adapter.IsScanning) { await adapter.StartScanningForDevicesAsync(); } if (deviceList.Count != 0) { for (int i = 0; i < deviceList.Count; i++) { DeviceSearch deviceSearch1 = new DeviceSearch(); deviceSearch1.Id = (deviceList[i]).NativeDevice.ToString();//Id.ToString(); deviceSearch1.Name = deviceList[i].Name; deviceSearches.Add(deviceSearch1); } } } private async void lv_ItemSelected(object sender, SelectedItemChangedEventArgs e) { try { if (lv.SelectedItem == null) { return; } device = lv.SelectedItem as IDevice; string asd = device.ToString(); await adapter.ConnectToDeviceAsync(device); } catch (DeviceConnectionException ex) { Debug.WriteLine("BLE connect DCE ex msg: " + ex.Message); Debug.WriteLine("e.Device.Name = " + device.Name); } }
The scan result don't work properly , this doesn't scan Samsung Level U device. Most of the devices are blank. I have used Plugin.Ble in the application.
While trying to connect a device , getting GattCallBack error .
First off all I am not getting every bluetooth devices, most of the devices contains blank name. Please suggest what should I do.
how to show Qr code using image view?
i am using ZXingBarcodeImageView for my app,
when i show up on phone, i am using ,
it is hard to move for my layout on my app.
please tell me how to use imageview for Barcode?
i put my code bellow,
public Customerinfo(string Parameter)
{
InitializeComponent();
NavigationPage.SetHasBackButton(this, false);
Navigation.PopAsync();
//this.Navigation.RemovePage(this.Navigation.NavigationStack[this.Navigation.NavigationStack.Count - 1]);
bar.Text = Parameter;
barcode = new ZXingBarcodeImageView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingBarcodeImageView",
};
barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
barcode.BarcodeOptions.Width = 300;
barcode.BarcodeOptions.Height = 300;
barcode.BarcodeOptions.Margin = 1;
barcode.BarcodeValue = Parameter;
stackPrinc.Children.Add(barcode); >> I don't wanna use it, wanna use imageview like image
} <StackLayout x:Name="stackPrinc"> >> I don't wanna use stackprint. <Image x:Name="LoginIcon" Source="HONGCHANG.jpg" Margin="0,40,0,0" /> <Label x:Name="bar" FontSize="45" /> <Button x:Name="Btn_Register" Text="Change password" Clicked="change"/> <Button x:Name="Btn_Logout" Text="Log Out" Clicked="Logout"/> </StackLayout>
EF Core database creation with Bindable models.
I built an app using Xamarin.Forms that used to CRUD using REST Api services. In that, I fetch data from service and map that onto a bindable object. Ultimately that object is a property on ViewModel. So I directly bind that on View. Everything works great.
To give an example, here is the model:
public class IdentityUser : BindableObject { public int CompanyID { get; set; } public string CompanyName { get; set; } }
Here is the ViewModel:
public class LoginViewModel : ViewModelBase { private IdentityUser _target; public IdentityUser Target { get { return _target == null ? _target = new IdentityUser() : _target; } set { _target = value; RaisePropertyChanged(() => Target); } } }
And I bind this Target with View directly:
<TextBox Text="{Binding Target.CompanyName}" />
Notify property changes and all other MVVM stuff works perfect.
Now the requirement is to provide offline capability in the same app. I thought I will simply use EF Core and create database tables using my same models. And while CRUD, I will handle the logic to go to local database or server depending on internet & data availability.
But this is not working. When I try to create DbSet using same models (Which are inherited by BindableObject), EF Core also adds the BindableObject properties e.g. IDispatcher, BindingContext, etc. along with my model properties. And I get error like this:
System.InvalidOperationException: The property 'IdentityUser.Dispatcher' is of an interface type ('IDispatcher'). If it is a navigation property manually configure the relationship for this property by casting it to a mapped entity type, otherwise ignore the property using the NotMappedAttribute or 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
This has become a nightmare for me now. I need to keep the previous app working along with this offline capability. I was looking for database first approach like Entity Framework 6 to be used in Xamarin.Forms but couldn't found anything like this. Any ideas how can I achieve my goal with minimal code changes?