Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 91519 articles
Browse latest View live

Picker shows multiple times

$
0
0

if you have multiple pickers on a page like Picker 1, picker 2 ... when you click on picker 1 and select something it works fine, but if you click and select something from second picker the first picker shows by itself. it is happening in XF 3.4.0.1008975 but it is ok in XF version 3.1.0.583944.

Do we have any fixes on its way?


Navigation bar color is not set 'Transparent' in Xamarin Forms iOS.

$
0
0

I have set Background image for whole application, and set navigation bar background color transparent. In android it's working proper. But in iOS Navigation Bar displays in white color.

iOS app when not debugging will no longer open after a few days

$
0
0

On iOS (iPhone and iPad devices) I can deploy, debug my app fine. The app can also be run without debugging via VS and XCode like published apps can. After a few days my app will not run standalone, it starts up (splash screen shown) then is terminated. Any idea how I can stop this happening?

Reason I ask is I auto provision my business partners iPhone to put the latest app on there once a week, so he can test it as he lives 10 miles away and I have not yet got an Apple dev account so I cannot use something like Test Flight or Hockey App. Same thing happens on my iPhone as seen as I connect it to XCode via VS and debug it works again

Thanks In Advance

Application.Resources StaticResource not found for key

$
0
0

Hi,

I am trying to define a Style for a custom control I have created in the Application.Resources section of my App.xaml.cs file. However the page that references this file raises an exception (StaticResource not found for key).

The sample here :-

https://github.com/xamarin/xamarin-forms-samples

Doesn't use a Key or a Custom Control for it's Application.Resources so I am not exactly sure how to get this working.

Is there any more comprehensive examples available or any pointers as to how to get this working?

Update: The same Style defined in the Page's Resources section, works successfully.

Thanks

Paul Diston

Build an app to runnable

$
0
0

Hey Everyone
I can run app in my device vis USB with visual studio.
But when I am sharing this app,I cant open app and showing error message "app has stopped" :disappointed:
How can I do this app to runnable in all versions of android phone and can share this app
Provide me solution
Thanks

Dynamically change the toolbar icon doesn't work in iOs

$
0
0

On my *.xaml file, I delcare many ToolbarItem and for each item, I declare an "OFF" and a "ON" Item, like this:

<ToolbarItem Text="run"
         Order="Primary"
         Clicked="OnToolbarItemClicked"
         x:Name="run">
  <ToolbarItem.Icon>
    <OnPlatform x:TypeArguments="FileImageSource"
                iOS="run.png"
                Android="ic_action_run.png" />
  </ToolbarItem.Icon>
</ToolbarItem>

<ToolbarItem Text="run"
             Order="Primary"
             Clicked="OnToolbarItemClicked"
             x:Name="runOn">
  <ToolbarItem.Icon>
    <OnPlatform x:TypeArguments="FileImageSource"
                iOS="run_on.png"
                Android="ic_action_run_on.png" />
  </ToolbarItem.Icon>
</ToolbarItem>

Then, I created a function to clear and reset the toolbar with the good items, like this :

    private void ResetToolbarItems()
    {
        ToolbarItems.Clear();

        if (IsRunning)
            ToolbarItems.Add(runOn);
        else
            ToolbarItems.Add(run);
    }

I also tried before to declare only one icon like this :

<ToolbarItem Text="run"
         Order="Primary"
         Clicked="OnToolbarItemClicked"
         x:Name="run">
  <ToolbarItem.Icon>
    <OnPlatform x:TypeArguments="FileImageSource"
                iOS="run.png"
                Android="ic_action_run.png" />
  </ToolbarItem.Icon>
</ToolbarItem>

and change it when OnToolbarItem was triggered :

    async void OnToolbarItemClicked(object sender, EventArgs args)
    {
        ToolbarItem toolbarItem = (ToolbarItem)sender;

        if (toolbarItem.Text == "run")
        {
            IsRunning= !IsRunning;
            ShowRunningIcon(toolbarItem);
        }
    }

There was my ShowRunningIcon :

    private void ShowRunningIcon(ToolbarItem toolbarItem)
    {
        if (IsRunning)
            Device.OnPlatform(  iOS: () => toolbarItem.Icon = "run_on.png", 
                                Android: () => toolbarItem.Icon = "ic_action_run_on.png");
        else
            Device.OnPlatform(  iOS: () => toolbarItem.Icon = "run.png", 
                                Android: () => toolbarItem.Icon = "ic_action_run.png");
    }

This is working on Android, but in iOs, the icon is not changing dynamically.

Could anybody help me with that?

Thanks,

Phil

How To Solve Unhandled Exception: System.FormatException: Input string was not in a correct format.

$
0
0

I am working on TextChanged event on Entry field. But It is showing Unhandled Exception: System.FormatException: Input string was not in a correct format.
occurred.
Anyone suggect me where i am wrong.

I can't deploy iOS app to simulator or my iPhone

$
0
0

I built an iOS app successfully. When I try to deploy it to debug, I get the following message:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

Then nothing happens; the app is not deployed to the device.

however, it does say "[Inspector] Error preparing project for inspection" in the output, I dont know if this is preventing the launch/deployment ... :(


Camera 2 Android

$
0
0

I am looking correct example for using implementing camera2 on android ,

Problem with ListView border in iOS

$
0
0

Hello everyone, I have a simple problem that I can't see where I'm making it wrong, the border between items on my listview has a Margin on the left side that I don't want, can anyone give me some light? Below is the Image and the XAML.

EDIT: I just realized it just have this margin on iOS, on Android is working great.

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage
        x:Class="AirSenseApp.View.PlacesMenuPageX"
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:b="clr-namespace:Corcav.Behaviors;assembly=Corcav.Behaviors"
        Title="Locais">
        <b:Interaction.Behaviors>
            <b:BehaviorCollection>
                <b:EventToCommand Command="{Binding AppearingCommand}" EventName="Appearing" />
            </b:BehaviorCollection>
        </b:Interaction.Behaviors>
        <ContentPage.ToolbarItems>
            <ToolbarItem
                Command="{Binding CreatePlaceCommand}"
                Icon="plusIcon.png"
                Order="Primary"
                Priority="1" />
        </ContentPage.ToolbarItems>
        <ContentPage.Content>
            <ScrollView>
                <StackLayout VerticalOptions="CenterAndExpand">
                    <ListView ItemsSource="{Binding PlacesList}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <ViewCell.View>
                                        <StackLayout
                                            HeightRequest="60"
                                            HorizontalOptions="StartAndExpand"
                                            Orientation="Horizontal">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="0.2*" />
                                                    <ColumnDefinition Width="1*" />
                                                    <ColumnDefinition Width="1*" />
                                                </Grid.ColumnDefinitions>
                                                <Image
                                                    Grid.Column="0"
                                                    Aspect="AspectFill"
                                                    HeightRequest="50"
                                                    Source="{Binding ImageResourceId}"
                                                    VerticalOptions="Center"
                                                    WidthRequest="50" />
                                                <Label
                                                    Grid.Column="1"
                                                    FontAttributes="Bold"
                                                    FontSize="Large"
                                                    Text="{Binding name}"
                                                    VerticalTextAlignment="Center" />
                                                <Label
                                                    Grid.Column="2"
                                                    FontAttributes="Bold"
                                                    FontSize="Large"
                                                    HorizontalOptions="EndAndExpand"
                                                    Text="23°C 49%"
                                                    VerticalTextAlignment="Center" />
                                            </Grid>
                                        </StackLayout>
                                    </ViewCell.View>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                    <Button
                        Command="{Binding ClearDBCommand}"
                        Style="{StaticResource acessButtonStyle}"
                        Text="Limpar BD" />
                </StackLayout>
            </ScrollView>
        </ContentPage.Content>
    </ContentPage>

When is it a bad practice to use Value Converter?

$
0
0

In my ViewModel, I have a ObservableCollection of Orders. Order model has statuses like started, finished, cancelled. I bind the collection to a ListView to display the orders and I want to color the row according to the status.

Would it be a good solution and not violate MVVM principles if I would write a value converter to do it? I would map the statuses to the colors and use that value converter when binding the color of a row.

I'm asking this question, because all examples of value converters are very primitive (changing the format of a DateTime and etc.) and my suggested value converter would contain several if statements or a switch.

Are there any other alternative ways to achieve my desired behavior?

How to Use deleteasync method with JSON and URI

$
0
0

hii community....
i Need to delete a record using id
for that purpose i need to pass JSON and URL
but DeleteAsync not considering JSON

How to Solve
if any please reply

Visual Designer for Xamarin Forms - Blend or an alternative?

$
0
0

Hi.

I was looking for a Visual designer for Xamarin forms.

I tried loading up Blend but there was no Visual Designer for the XAML just I could just see that XAML code.
This is unlike a UWP app where this seems possible.

Are there any other options. I am looking for an easy way to prototype for a designer type person to use.

Or is the only way to do it in Visual Studio and manually do the XAML.

If this is the case are there any other plans that Microsoft has to enhance Blend to make this work.

Thanks,

Ward.

Text to speech is not read when navigate to other screen or click on back button in Xamarin forms

$
0
0

Hi Guys,

I am Implemented Text to speech functionality using Xamarin forms Essentials package, Text to speech is not read when we navigate to other screen or click on back button.

I have 5 pages in my Application, suppose I am in SecondPage before reading speech content in the Second page when i navigate to third page or press back button Text to Speech is not working.

Can anyone help on this.

Thanks,
Srinivasu

Xamarin Forms - Android - Set Toolbar Title to Center

$
0
0

I am developing Xamarin forms app.
In Android, I know, the toolbar title is in left by default.

I need it to be in center aligned like iOS.

Below is my code which I tried:

Toolbar.axml: in layout folder

    <?xml version="1.0" encoding="UTF-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/toolbar"
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"
       android:background="?attr/colorPrimary" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
       android:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <TextView
            android:id="@+id/tabIcon"
            android:layout_width="wrap_content" 
            android:layout_gravity="center_horizontal"
            android:layout_height="wrap_content"
            android:paddingTop="2dp"
            android:background="@android:color/holo_red_dark"/>
    </android.support.v7.widget.Toolbar>

Android Custom Renderer class:

[assembly: ExportRenderer(typeof(Page), typeof(CustomPageRenderer))]

namespace Assure.Droid
{
    public class CustomPageRenderer : PageRenderer
    {
        global::Android.Views.View view;
        Activity activity;

        public CustomPageRenderer(Context context) : base(context)
        {
        }
    protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            { 
                return;
            }

            try
            {
        activity = this.Context as Activity;
                view = activity.LayoutInflater.Inflate(Resource.Layout.Toolbar, this, false);
                var imageView = view.FindViewById<TextView>(Resource.Id.tabIcon);
                imageView.Text = page.NewElement.Title;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(@"ERROR:", ex.Message);
            }
        }
     }
}

I have stuck in my deliverables. Please kindly help me guys. :)


Sample ToDo - Downloaded - How do I execute

$
0
0

I have downloaded the sample ToDo List. There are many members in the folder. What member do I click to execute the sample?

Xamarin.Forms can not hide IpHONE X Home Indicator.

$
0
0

I am building a Video Player app using Xamarin.Forms

about prefershomeindicatorautohidden api from UIViewController

I tried on Xamarin.iOS create new single page project override PrefersHomeIndicatorAutoHidden property on ViewController class works fine, Home Indicator auto hidden after specific seconds
and debug break point are hit (means iOS are query that property).

public override bool PrefersHomeIndicatorAutoHidden => true;

but in Xamarin.Forms there is no UIViewController controller to override that property. so must write a custom renderer for ContentPage.

So i try to create Custom Renderer for ContentPage which inherit from PageRenderer which inherit from UIViewController. override PrefersHomeIndicatorAutoHidden to true and ChildViewControllerForHomeIndicatorAutoHidden to "this"

public override bool PrefersHomeIndicatorAutoHidden => true;
public override UIViewController ChildViewControllerForHomeIndicatorAutoHidden => this;

the property never called by iOS, break point never hit, Home Indicator always show on screen, but my app is a Video Player, that's a problem. i can sure this Custom Render works because it can
hit ViewDidLoad() method debug break point.

your can reproduce this problem by Create New Project should be simple.

or maybe i miss some thing, and i have been try to Xamarin.Forms repo to find some clue,
and i saw Source Code on PageRenderer implenment

public override bool PrefersStatusBarHidden()

but do have not override PrefersHomeIndicatorAutoHidden property. please help me , thanks a lot.

How to stop audio on webview when backing out to prior page in app. (iPad )

$
0
0

When viewing a webpage thru a webview that is playing audio, lets say like a youtube video, and I return to the parent page in the app, the audio continues to play. This is happening even though that page is gone. So, are there any ideas how to stop this from playing? I am assuming something needs to be put in the OnDisappearing method on the page with the webview control? I tried to give the Webview control a name in the xaml and set the source property programmatically to another url (this will turn off the audio if it is navigated) but navigation was not kicked in. I am using webview renderers as well and tried to dispose there too, but to no avail. Using Xamarin Forms 1.3.2.6316 on vs 2013 update 5ctp. Thanks in advance.

protected override void OnDisappearing()
{
base.OnDisappearing();
.... what do I put here?
}

Renaming or Refaco

$
0
0

I am not sure if this is the proper forum for this, however it is specific to Xamarin Forms so I thought I would share this here. Sometimes I have a need to rename a Xamarin Content page. Typically during the rename there two things I wish to achieve:
1) I wish to rename the specific files to their new names.
2) I wish to have the code in the code behind also reflect the new names.

The behavior I see though in Visual Studio (version 15.9.5) is not at all what I would expect. Here is the process I wish I could follow, as well as the process I have to follow to actually get a Content page renamed successfully.

Take the example of renaming a Xamarin Content page called "AppContentPage" which consists of three files:
AppContentPage.xaml
AppContentPage.xaml.cs
AppContentPage.xaml.g.cs

What I wish could happen:
I right click on the Content page file name in solution explorer, I type in the new name and press enter. I wish all three pages would rename then all the code behind (including the xaml) that shares that same name would also be updated.

What actually happens:
Visual Studio invariably renames all three file names, sometimes it attempts to change the code behind but often times it fails, even if the code behind mirrors the file name. This is "livable" since I can just go to the code behind in the xaml.cs file and rename the class, again by right clicking the class name and choosing rename. The most annoying part however, is, regardless of whether I rename the class manually or if visual studio does it automatically, the class name in the .xaml page does not get renamed. Visual Studio does not inform you of this. Instead everything "appears" to have been renamed on the surface so you may even attempt to rebuild shortly after renaming the file or renaming the class name in .xaml.cs file. This causes the project to fail a rebuild with the error "The name 'InitializeComponent' does not exist in the current context"

At first you may think that the .xaml.g.cs file did not get recreated. Upon examining the obj directory though you will find that the file did in fact get created correctly. As mentioned, the problem is that the .xaml file still has the old class name at the top of the file. The fix is easy, provided you know what to look for.

To correct the problem you must open the .xaml file and rename the Class name. For example if I renamed the above mentioned files to AppContentPage2.xaml I would need to modify this xaml:

ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App2.AppContentPage"

To this:
ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App2.AppContentPage2"

I hope this helps someone deal with this annoying bug in Visual Studio when renaming a Xamarin Content Page.

Xamarin - Entity Framework - SqLite - GetItemsAsync : unable to open database file

$
0
0

Xamarin - Entity Framework - SqLite : unable to open database file


In Visual studio 2017, I created a Cross-Platform Mobile App (Xamarin.Forms)

NETStandard 2.0
Microsoft.Data.Sqlite.Core 2.2.0
Microsoft.EntityFrameworkCore 2.2.0
Microsoft.EntityFrameworkCore.Sqlite 2.2.0
Microsoft.EntityFrameworkCore.Tools 2.2.0

I did a code first migration to Sqlite with Entity Framework. All tables are created successfully. The database was seeded.

When I try to get the ItemsViewModel (see code below), I get the following exception (after 20 seconds) on the line --> List item list1 = await db.Person.ToListAsync();

Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 14: 'unable to open database file'. at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db) at Microsoft.Data.Sqlite.SqliteConnection.Open() at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)

Strangely enough my method TestSqLiteDataStoreAsync (see code below) correctly returns the expected list of items.

Below you will find the relevant code. If you need anything more, let me know.


[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ItemsPage : ContentPage
{
    ItemsViewModel viewModel;

    public ItemsPage()
    {
        InitializeComponent();
        //1 code starts here
        BindingContext = viewModel = new ItemsViewModel();
    }

    async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
    {
        var item = args.SelectedItem as Item;
        if (item == null)
            return;

        await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(item)));
        ItemsListView.SelectedItem = null;
    }

    async void AddItem_Clicked(object sender, EventArgs e)
    {
        await Navigation.PushModalAsync(new NavigationPage(new NewItemPage()));
    }


    //adding 'async' did not solve the problem
    protected async override void OnAppearing()
    {
        base.OnAppearing();

          if (viewModel.Items.Count == 0)
            //2 code continues here 
            viewModel.LoadItemsCommand.Execute(null);
    }
}



public class ItemsViewModel : BaseViewModel
{
    public ObservableCollection<Item> Items { get; set; }
    public Command LoadItemsCommand { get; set; }

    public ItemsViewModel()
    {
        Title = "Browse";
        Items = new ObservableCollection<Item>();

    //3 code continues here 
        LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommand());

        MessagingCenter.Subscribe<NewItemPage, Item>(this, "AddItem", async (obj, item) =>
        {
            var newItem = item as Item;
            Items.Add(newItem);
            await DataStore.AddItemAsync(newItem);
        });

    }

    //My test method
    public async Task<List<Item>> TestSqLiteDataStoreAsync()
    {
        SqLiteDataStore SqLiteDataStore = new SqLiteDataStore();
         return await SqLiteDataStore.GetItemsAsync(false);
    }



    async Task ExecuteLoadItemsCommand()
    {
        if (IsBusy)
            return;

        IsBusy = true;

        try
        {
            Items.Clear();
    //4 code continues here 
            var items = await DataStore.GetItemsAsync(true);
            foreach (var item in items)
            {
                Items.Add(item);
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
        finally
        {
            IsBusy = false;
        }
    }
}

public class SqLiteDataStore : IDataStore
{
public string dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
public string fileName = "TestSqLite.db";

    public SqLiteDataStore()  { }

    public async Task<List<Item>> GetItemsAsync(bool forceRefresh = false)
    {
        try
        {
            using (var db = new Models.MyContext(Path.Combine(dbFolder, fileName)))
            {
                List<Person> list1 = new List<Person>();
                List<Item> list2 = new List<Item>();

                //5 I get the error here
                list1 = await db.Person.ToListAsync();

                foreach (Person person in list1)
                {
                    Item item = new Item(person);
                    list2.Add(item);
                }
                return list2;
            }
        }
        catch (Exception)
        {
            throw;
        }
     }


    public async Task<bool> AddItemAsync(Item item)
    {
       throw new NotImplementedException();
    }

    public Task<bool> UpdateItemAsync(Item item)
    {
        throw new NotImplementedException();
    }

    public Task<bool> DeleteItemAsync(string id)
    {
        throw new NotImplementedException();
    }

    public Task<Item> GetItemAsync(string id)
    {
        throw new NotImplementedException();
    }
}
Viewing all 91519 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>