I am currently on Xamarin PCL . when initializing the controls of xaml( using Findbyname<>, everything is returned as null.
The same works well on android and iOS.
Findbyname returns null in xamarin.winPhone
Open local files in xamarin.forms
I need to open local file, here is my solution in Android project.
Intent intent = new Intent(Intent.ActionView);
var file = new File("content://" + path);
var uri = FileProvider.GetUriForFile(Application.Context, BuildConfig.ApplicationId + ".provider", file);
intent.SetDataAndType(uri, GetMimeType(path));
intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
But file provider don't work and app crashes without any errors. I need to add provider to my androidmanifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
But how can I add this in xamarin.forms, I don't have android manifest file.
MainPage.xaml.cs sharing with MainActivity.cs
I noticed I can only access objects (labels etc...) from MainPage.xaml.cs.
Certain things, like a NuGet Bluetooth pacakage i have (Plugin.BLE) Can only be referenced in MainActivity.
So, what I need, is either a way to use my Plugin.BLE in MainPage.xaml.cs...
Or, to be able to access my label etc, from MainActivity.
Any help?
Toolbar item text change dynamically
Toolbar item text change dynamically in xamarin forms, is it possible? I am using MVVM pattern to update the text,but the text was not updating......
Thanks in advance...
Troubleshooting "too many open files" exception in iOS version of xamarin.forms app
We develop apps for iOS and Android using xamarin.forms. In appcenter, it turns out that one of our apps sporadically crashes in iOS with an error: "System.IO.IOException: Too many open files".
We've been googling on what causes this issue. We checked all our code, and we made sure (as far as we can find) that all filestreams are properly closed and disposed after usage. We also found that the garbage collector of iOS can be too late in collecting the streams, so we added a manual GC.Collect() call in the methods using filestreams.
However, the issue still seems to appear. Is there a way we can monitor if any file handles are not being closed, so we can find out why this error still occurs?
Some info that might be relevant for troubleshooting suggestions:
- We're using Xamarin.Forms
- We're using Visual studio 2017 on Windows PC
- We have a mac connection in Visual studio to be able to build and debug the iOS version of our app
The full stacktrace of the crash:
System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) <0x105032c20 + 0x005c8> in :0 System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean anonymous) <0x105032b70 + 0x0008f> in :0 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.IsolatedStorage.IsolatedStorageFile isf) <0x10503beb0 + 0x00057> in :0 System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.IsolatedStorage.IsolatedStorageFile isf) <0x10503c000 + 0x00067> in :0 IsolatedStorageFile.OpenFile (System.String path, System.IO.FileMode mode) Deserializer+<>c.b__1_0 () Task1[TResult].InnerInvoke ()
Task.Execute ()
ExceptionDispatchInfo.Throw ()
TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () Application+d__69.MoveNext ()
XML without root element
I want to consume web api and print the output on xamarin forms. web api returns output in xml format. however it does not have a root element.
XML format is something like this:
Is this a valid format?
A
a /a
b /b
/A
A
a /a
b /b
/A
XDocument.parse gives null.
Exception message is Data at the root level is invalid.
Is it possible to add root element to web api which is deployed on server?
how should i convert xml to json?
Excuse the formatting. Text disappears if i use<> tags
I'm getting build error in my project
This is my project https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences and This is the error I"m getting
Severity Code Description Project File Line Suppression State
Error The project file "............\source\XamarinForms\Xamarin.Auth.Forms\Xamarin.Auth.Forms.csproj" was not found. ComicBook
Severity Code Description Project File Line Suppression State
Error The project file "............\source\Xamarin.Auth.Portable\Xamarin.Auth.Portable.csproj" was not found. ComicBook
Please help me. Ur help will be appreciated.
Best way to pass info back to previous page
Hello there!
I'm solving troubles by my own, but sometiems I need some advices.
I have to select a list of items, so I create a ListView page, got its ViewModel with a list, and when I got all done, you tap "Ok"and I delete items not selected from the list. Now I need to pass this list to the parent page to work with it.
I found some solutions, but I wonder what is the best:
- First option is: parent page has the instance of the child's ViewModel because it was the one who create it. So my first option was to use OnAppearing to check if the child ViewModel exists and it has any element remaining in it's list, to grab them and do whatever it needs.
- My second though was to pass the parent ViewModel to the child as a parameter, and when the child work is done, call a parent ViewModel command with the selected item list to work with, and when it finish, use Navigation.PopAsync().
- Lastly, I read some more, and I found Navigation.GoBackAsync. It looks good because it can call the parent ViewModel command when it's returning only from a child, but I'm not sure if it works the same way as PopAsync method but adding an event and parameters.
What's the best option to get the code as simple as possible (keep in mind that I'm a noob in Xamarin and I'm learning bit by bit ^^U).
Thank you!!
Using xamarin forms mvvm how to set tab bar at bottom of the page in android like as ios?
I working on xamarin forms using MVVM. I want to set tabs on bottom in android like as tabs on iOS. If any one have idea about that let me know.
Thanks in advance
how to integrated the complex css website in xamarin.form?
Hi, we had one web application build with complex CSS & business logic layer in Asp.net. Now as per requirement we want to build mobile application for same website using existing CSS & class file. The site is already mobile responsive, but we want to create hybrid mobile application with native look and feel. Hence we are looking for solution in xamarin cross platform.
Custon Render for ToolbarItens
Hello Every body
I need to implement a rounded icon in nav bar like whatsapp photo profile
Can help me please...
How can i do a custon render for toolbaritens round icon
Twoway binding for object properties not working
This is my Xaml
<Image Grid.Column="0" Grid.Row="0" Source="contactIcon.png" />
<Entry Grid.Column="1" Grid.Row="0" Text="{Binding SelectedContact.FNAME,Mode=TwoWay}" Placeholder="First Name" />
<Entry Grid.Column="1" Grid.Row="1" Text="{Binding SelectedContact.LNAME,Mode=TwoWay}" Placeholder="Last Name"/>
<Image Grid.Column="0" Grid.Row="2" Source="calIcon.png" />
<Entry Grid.Column="1" Grid.Row="2" Text="{Binding SelectedContact.PHONE,Mode=TwoWay}" Placeholder="Mobile" Keyboard="Telephone"/>
<Image Grid.Column="0" Grid.Row="3" Source="emailIcon.png" />
<Entry Grid.Column="1" Grid.Row="3" Text="{Binding SelectedContact.EMAIL,Mode=TwoWay}" Placeholder="Email" Keyboard="Email"/>
<Entry Grid.Column="1" Grid.Row="4" Text="{Binding SelectedContact.BALANCE,Mode=TwoWay}" Placeholder="Email" Keyboard="Email"/>
Contact model
public int ID { get; set; }
public string FNAME { get; set; }
public string LNAME { get; set; }
public string PHONE { get; set; }
public string EMAIL { get; set; }
public Double BALANCE { get; set; }
ContactViewModel
private Contact _selectedContact;
public Contact SelectedContact{get { return _selectedContact; }set{
_selectedContact = value; OnPropertyChanged(); } }
OneWay binding is working but i want twoway binding. If i change the text or modify the text in the firstname entry then it should change the FNAME property of SelectedContact.
How would I make a custom round label renderer auto size to its width of text?
How would I make a custom rounded label renderer resize based on the width of the label inside it? I always want a little space to the left and right of the text.
Implementation of Google Sign-In sdk in xamarin.forms
Hi I am trying to create Google Sign In using the Google Sign In SDK as Google has updated its security restrictions for OAuth flow. They are not going to allow native web-views to initiate OAuth flows. I want to use the Google Sign In Sdk in xamarin forms for both android and ios. If any one has already implemented it then please share the information or code for it.
Title of the content page is not displayed
I have updated to lates version of Xamarin.Forms and title defined in Content page is not displayed in Android. The content page is added correctly:
MainPage = new NavigationPage(new Jobs());
Title is populated by IMarkupExtension
that pulls the value from a resource file. At first I thought this might not be working but a quick debugging session proved me wrong. I have also tried to put static text in this property but again, it is not displayed.
Has anything changed in the new version that would break my code?
changing Grid.IsVisible to true: child views remain invisible
I have a GridLayout with some child views in it, and initially the grid is invisible (and collapsed), because I set "IsVisible" to false.
Then I have a button to toggle the visibilty of the grid, and when I toggle it for the first time, ie. set IsVisible=true, the grid is not collapsed any more, but all children in it are not visible, there is just a white background. But when I toggle it again (IsVisible=false) and then again (the second time) to IsVisible=true, all child views are visible. I also tried "grid.ForceLayout()" after setting IsVisible to true, but it has no effect.
Any solution to that ?
Problem with using Grid.IsVisible
Hi there
It turned out the Grid.IsVisible (iOS part) works only one way: when IsVisible=true, it appears.
If set IsVisible=false, it hides but holds the place of the same size it had. Just blank ugly void.
Nevertheless, the Xamarin doc reads:
Setting IsVisible to false will remove the element from the visual tree. The element will no longer take up space in layouts or be eligle to receive any kind of input event
Apparently, it is a bug.
Any clue how to work around?
Thanks.
ListView databinding just won't work
I have the following page in XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="ht_tp://xamarin.com/schemas/2014/forms"
xmlns:x="ht_tp://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:DietAndFitness.ViewModels"
x:Class="DietAndFitness.Views.FoodDatabasePage">
<ContentPage.Content>
<StackLayout>
<ListView ItemsSource="{Binding FoodItems}" RowHeight="120">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ContentView Padding="5">
<Frame OutlineColor="Accent" Padding="10">
<StackLayout>
<Grid HorizontalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Name}" FontSize="22" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Grid.Row="0" Grid.Column="0"/>
<Label Text="{Binding Calories}" FontSize="22" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Grid.Row="0" Grid.Column="1"/>
</Grid>
<Grid HorizontalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Text="Carbohydrates" Grid.Row="1" Grid.Column="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="16"/>
<Label Text="Proteins" Grid.Row="1" Grid.Column="1" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="16"/>
<Label Text="Fats" Grid.Row="1" Grid.Column="2" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="16"/>
<Label Text="{Binding Carbohydrates}" Grid.Row="2" Grid.Column="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="16"/>
<Label Text="{Binding Proteins}" Grid.Row="2" Grid.Column="1" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="16"/>
<Label Text="{Binding Fats}" Grid.Row="2" Grid.Column="2" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontSize="16"/>
</Grid>
</StackLayout>
</Frame>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Grid HorizontalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="AddFoodItemButton" BackgroundColor="LightGray" HorizontalOptions="CenterAndExpand" Text="Add" Grid.Row="0" Grid.Column="0" Clicked="AddFoodItemButton_Clicked" />
<Button x:Name="EditFoodItemButton" BackgroundColor="LightGray" HorizontalOptions="CenterAndExpand" Text="Edit" Grid.Row="0" Grid.Column="1" />
<Button x:Name="DeleteFoodItemButton" BackgroundColor="LightGray" HorizontalOptions="CenterAndExpand" Text="Delete" Grid.Row="0" Grid.Column="2" />
</Grid>
</StackLayout>
</ContentPage.Content>
And this is the code behind:
public FoodItemsViewModel FoodDatabase { get; set; }
public FoodDatabasePage ()
{
InitializeComponent ();
FoodDatabase = new FoodItemsViewModel(SQLiteConnection.Database);
BindingContext = FoodDatabase;
}
protected override void OnAppearing()
{
FoodDatabase.LoadList();
}
public void AddFoodItemButton_Clicked(object sender, EventArgs e)
{
FoodDatabase.Add();
}
But my ListView just comes up empty. The only way I've managed to get the list populated is if I do
<ListView ItemsSource="{x:Static local:FoodItemsViewModel.FoodItems" RowHeight="120">
And make the ObservableCollection in my VM static. This is my VM:
public class FoodItemsViewModel
{
private SQLiteAsyncConnection database;
public ObservableCollection<GlobalFoodItem> FoodItems { get; set; }
public FoodItemsViewModel(SQLiteAsyncConnection _database)
{
database = _database;
}
public async void LoadList()
{
FoodItems = new ObservableCollection<GlobalFoodItem>(await database.Table<GlobalFoodItem>().ToListAsync());
}
public void Add()
{
FoodItems.Add(new GlobalFoodItem("Item"));
}
}
Even if I make my ObservableCollection static the list still doesn't actually load until I reload the page by navigating to another one.
Furthermore attempting to implement INotifyPropertyChanged in my VM results in StackOverflow exception at the ObservableCollection getter (I already implemented INotifiyPropertyChanged in the GlobalFoodItem class, maybe it has something to do with it?).
Also, here is the github for the project htt_ps://github.com/TJorj/DietAndFitness
I have no idea what's going on anymore. How can I get this thing working properly?
File upload, is this possible?
I have an application that is coming along very nicely. However, looking online one of my app requirements requires the ability to take a photo/small file (.doc,.csv,.pdf), nothing huge.
And upload it to our system. I can do this via a web api 2.0 call or something else.
How can I achieve this in an elegant way?
Thanks in advance!
Local XAML namespace in Shared project
Hello,
I tried to declare a local XAML namespace in my pages in a Shared Xamarin.Forms project like this :
xmlns:local="clr-namespace:MyProject.Example;assembly=MyProject.Example"
It doesn't work, and that is obvious because a Shared project isn't built but its content is copied in other projects with different assemblies (MyProject.Example.iOS
, MyProject.Example.Android
, ...).
How can I achieve this ?
Thank you !