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

How to select multiple images from gallery for android and IOS device and how to show it in the UI?

$
0
0

Same thread found here. But the answer is not complete.

Android part multiple image selection is working with that code, but didn't tell how to show the selected images in UI?

For IOS suggesting to install ELCImagePicker, but that Nuget is not available in Nuget store.

So anybody please suggest a solution for this feature?


How to remove the selected item from FlowListView?

$
0
0

I need to remove the selected picture when clicks a cross image. For that, I added a cross image on top of the image and added the tapped event. I am showing the images in FlowListView.

MainPage.xaml

<flv:FlowListView 
        FlowColumnCount="3" 
        x:Name="listItems" 
        SeparatorVisibility="None"
        HasUnevenRows="false" 
        RowHeight="100" >
        <flv:FlowListView.FlowColumnTemplate>
            <DataTemplate>

                <StackLayout
                    Orientation="Vertical">

                    <Image 
                        Source="ic_close.png"
                        HeightRequest="20"
                        WidthRequest="20">
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer
                            Tapped="RemoveImage"
                            NumberOfTapsRequired="1" />
                        </Image.GestureRecognizers>
                    </Image>

                    <Image 
                        AbsoluteLayout.LayoutFlags="All" 
                        HeightRequest="100" 
                        AbsoluteLayout.LayoutBounds="0,0,1,1" 
                        Source="{Binding .}"  
                        Aspect="AspectFill" 
                        HorizontalOptions="FillAndExpand">
                    </Image>
                </StackLayout>
            </DataTemplate>
        </flv:FlowListView.FlowColumnTemplate>
    </flv:FlowListView>

MainPage.xaml.cs

 public partial class MainPage : ContentPage
 {
    List<string> _images = new List<string>();
    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", (s, images) =>
        {
            listItems.FlowItemsSource = images;
            _images = images;
        });
    }

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        MessagingCenter.Unsubscribe<App, List<string>>(this, "ImagesSelected");
    }

    public void RemoveImage(Object sender, EventArgs args)
    {
        // How I can remove the selected image from the FlowListView
    }
}

Anybody, please suggest a way to remove that image from FlowListview?

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?

How can I change an Image Border color on hover in Xamarin?

$
0
0

I need to change an image's border color on hover and remove the border when the hover is removed. Is there a way to do this in Xamarin?

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.

WebView HtmlWebViewSource crashing the app

$
0
0

Hello,

I want to display html text using webview. Currently I am testing it on UWP. Problem is whenever I use WebView in my current XAML code it's crashes the app and throw exception on the last page. I even tried using some hard quote value but even that's not working.

My XAML Code:

<ContentPage.Content>

        <Image x:Name="ProductDetailsImage" WidthRequest="200" HeightRequest="200"></Image>
        <Label x:Name="ProductDetailsName" ></Label>
        <Label x:Name="ProductDetailsStartingFrom" ></Label>
        <Label x:Name="ProductDetailsBrand" ></Label>
        <Label x:Name="ProductDetailsSKU" ></Label>
        <Label x:Name="ProductDetailsMPN" ></Label>
        <Label x:Name="ProductDetailsStockStatus" ></Label>
        <Label x:Name="ProductDiscontinued" Text="Non-Returnable" IsVisible="False" ></Label>

        <Picker x:Name="SelectColorPicker" ItemDisplayBinding="{Binding name_str}" 
                SelectedItem="{Binding option_value_id}" IsVisible="False" Title="Select Color:"
                SelectedIndexChanged="SelectColorPicker_SelectedIndexChanged"></Picker>

        <Picker x:Name="SelectSizePicker" ItemDisplayBinding="{Binding name_str}"
                SelectedItem="{Binding option_value_id}" IsVisible="False" Title="Select Size:" 
                SelectedIndexChanged="SelectSizePicker_SelectedIndexChanged"></Picker>

        <Label Text="Enter Quantity: " x:Name="LabelQty" IsVisible="False"></Label>
        <Entry x:Name="ProductQty" Text="1" IsVisible="False"></Entry>
        <Button x:Name="AddToCart" Text="Add to Cart" IsVisible="False" Clicked="AddToCart_Clicked"></Button>
        <Button x:Name="AddToWishlist" Text="Add to Wishlist" IsVisible="False" Clicked="AddToWishlist_Clicked"></Button>     


        <WebView HeightRequest="100" WidthRequest="100">
            <WebView.Source>
                <HtmlWebViewSource x:Name="ProductHtmlWebViewSource"></HtmlWebViewSource>
            </WebView.Source>
        </WebView>

    </StackLayout>
</ContentPage.Content>

Code Behind:

ProductHtmlWebViewSource.Html = product.data.descriptions;

Any help would be appreciated.

Thank you

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();
    }
}

How to remove gaps in the splash with 9 patch images?

$
0
0

Dear,

After update my xamarin forms android app to use targetSdkVersion 27 (I don't remember surely but think that before was 16) my splash screen is shown with two rectangles and I don't found the cause, someone already dealed with this issue?

Printing rows of a xamarin.forms.listview in a UWP

$
0
0

Hi there,

Does anyone know how or know where I could look to find out how to print the rows of a xamarin listview in UWP? I've seen online examples of printing webviews, pdfs, images, etc., but I'm not sure how to print a listview. I'm using dependency injection and I'm just passing a parameter to my UWP implementation with the listview object.
Thanks

MvvmCross MvxTabbedPage documentation?

$
0
0

I'm trying to find documentation on the MvvmCross MvxTabbedPage. I can't find it in the MvvmCross documentation or GitHub repo - hopefully I'm just not looking in the right place!

Specifically, where (if possible) I can adjust the layout of the tab items - e.g. the font style and icon size used in the tabs.

Can someone point me in the right direction please?


Resource file or ResorceDictionary for storing colors

$
0
0

I am looking to keep custom color hex codes in either a .resx file or a resourceDictionary (.xaml) file so I can reuse it between views in my app. I know I can use resource files with strings for texts but it throws an error if I try the same way to pull a string containing the hex code for colors, it throws an error. What's the best way to do this?

Here's what I have in xml:

    <!--This doesn't work-->
    <StackLayout BackgroundColor="{x:Static CustColors.JsBlue}">

        <!--This works-->
        <Label Text="{x:Static resx:Texts.MainTitle}" 
               HorizontalOptions="Center"/>

    </StackLayout>

TapGestureRecognizer problems

$
0
0

I am new to mobile development, but have been a C# developer for years. I'm creating my first Xamarin Forms app and I cannot seem to grasp how to implement the TapGestureRecognizer. I have a "SignUp" label on the first page of my app. In its xaml I have the following code:

<Label.GestureRecognizers>

</Label.GestureRecognizers>

in my code behind cs page I have the following method:
void SignupGestureRecognizerTapped(object sender, EventArgs e)
{
Navigation.PushAsync(new signup());
}

The Xamarin forms previewer displays an error message saying there is no method "SignupGestureRecognizerTapped" on type "login". I'm assuming it's telling me it can't find the method that corresponds to the one listed in the xaml. I have rebuilt the solution multiple times and it will not deploy to the emulator without crashing.
Is there something I'm leaving out?
Thanks.

G

P.S.
I originally posted this in the Android forum and someone suggested I make the method in the code behind Public async with await in the call to the new page so that it looks like this:
Public async void SignupGestureRecognizerTapped(object sender, EventArgs e)
{
await Navigation.PushAsync(new signup());
}
This didn't seem to help. The method in my code behind is still not being seen.

UI code in both xaml and c# files

$
0
0

I was wondering if it was possible to have code for a content page where I could have static views made in the xml and have dynamically created views in the C# file. Most examples of writing UI content page code either has all the code in xaml or in c#, but I want to use C# to add views into layouts that already exist without overwriting the existing code.

Get UIBarButtonItem from ToolbarItem

$
0
0

So, I have a UIAlertController action sheet that I display using iOS-only code in my cross-platform Xamarin.Forms app. The action sheet is displayed when a Xamarin.Forms.ToolbarItem is tapped by the user. When on iPad, the UIAlertController containing the action sheet needs to have its UIPopoverPresentationController.BarButtonItem set to the menu item that caused it to appear, or I have to manually specify a location on screen where I want the action sheet to appear.

Is there no way of converting a Xamarin.Forms.ToolbarItem into its corresponding UIBarButtonItem?

I've tried for hours by intercepting calls to PageRenderer and NavigationRenderer to no avail, since the ToolbarItems properties of the respective native views are never set. I can see the Xamarin.Forms.ToolbarItems I provided at Xamarin.Forms.Page construction, however. I cannot use Platform.GetRenderer() as it requires a VisualElement, which Xamarin.Forms.ToolbarItem doesn't implement.

I also looked at Xamarin.Forms.Platform.iOS.ToolbarItemExtensions.ToUIBarButtonItem, which gives me a proper UIBarButtonItem from a Xamarin.Forms.ToolbarItem, but the provided item is a new such, and has no correspondence on screen. Using the returned item as a value for UIPopoverPresentationController.BarButtonItem causes the application to crash.

Any other ideas?

Can I send a value to my Webapi not to be stored in database but as a parameter to return data

$
0
0

Hi All,

So I am using web api to post data to a database on the server.. work great easy to understand how its working...
But in this case.. the users want to be able to send and Id via their devices and have that Id get processed and
return a value back to a list display on the device...

So and web api get.. but with a parameter... Is there some example I can follow showing how this can be done...
I am sure this is more a question for web api people

But I wanted to check here first.. because I was not sure how to refresh the page on the device if this can be done.

Thanks.

Viewing all 91519 articles
Browse latest View live


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