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

Is there a way to get XAML binding intellisense in a separate ContentView file used in a ListView?

$
0
0

I have a ListView with this item template:

<ListView.ItemTemplate>
  <DataTemplate>
    <ViewCell>
      <views:ProjectListEntry />
    </ViewCell>
  </DataTemplate>
</ListView.ItemTemplate>

ProjectListEntry is fairly complex and is used in another ListView, so I have it in its own file. I've set it up like this:

<ContentView
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    ...
    BindingContext="{x:Static helpers:DesignTimeData.ProjectListEntryVm}">

As you can see, to get Intellisense, I tried to set BindingContext to a static member on the DesignTimeData class. This works fine for my Pages (where I replace the BindingContext at runtime), but for ContentViews used in ListViews, the ContentView's BindingContext seems to be inherited (from the ViewCell, I guess). This means that the explicit BindingContext on my ContentView will actually override the BindingContext set on the ViewCell by the ListView, and all my list elements will reflect the static design-time data at runtime. But if I remove the BindingContext, I get no intellisense for the members I bind to inside the ContentView file.

Is there a simple way to get Intellisense for bindings in a ContentView like this? (As mentioned, I can't inline the ContentView in the ListView definition, because the ContentView is fairly complex and used in several lists. I also can't use some kind of VM locator, because although I'm using bindings, I'm not using "full" MVVM - I'm using a Redux-like architecture instead. And I guess a VM locator wouldn't work for this case anyway for the same reasons the above doesn't work.)


is there any update for xamarin.social is coming for .net standard 2.0 or suggest any alternative.

$
0
0

xamarin.social is targeting framework 4.6.1

Handling the tap events on image in xamarin.forms?

$
0
0

Can you anyone Please help me on this? How to handle the tap events on xamarin.forms. even i gave numbertaps required=2 in xaml it s executing number of times.
my scenario is image is in xaml page and i gave number taps required is "2" when i click on 2 times with no time its executing many times.

how to set (no of taps to) 1 in tap command in mvvm xamarin forms?

$
0
0

i have given tap gesture to image .... when i tapped image multiple times then page is also opening multiple times....i want to open page for only one tap...i have already given no of taps=1...but not working..how to do???

[Material] how to gain access to `Toolbar` from custom renderer?

$
0
0

Based on @TheRealJasonSmith's gist on how to add Material design to your Forms.Android app, I've implemented the "Toolbar" instead of the "ActionBar".

I'm wondering how I might go about getting access to that View in order to set the NavigationIcon to the Page.Icon?

Right now I've got a custom renderer that is attempting to set the Toolbar NavigationIcon like so, but toolbar is always null

[assembly: ExportRenderer(typeof(Page), typeof(Renderers.ExtendedPageRenderer))]
namespace Renderers
{
    public class ExtendedPageRenderer : PageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            if (Element != null && Element.Icon != null)
            {
                var iconId = ResourceManager.GetDrawableByName(Element.Icon.File);
                var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
                if (toolbar != null)
                {
                    toolbar.SetNavigationIcon(iconId);
                }
            }
        }
    }
}

Saving game data to SQLite

$
0
0

I have 6 populated instances of a rather lengthy class (6 columns of the players stats in a score sheet). Can someone please tell me the best way to save the 6 instances to Sqlite when the game terminates and then use SQLite to repopulate the instances when the players load the saved game?

Set Values in Picker depending on User Input (Dynamically add items to Picker)

$
0
0

I am using Xamarin Forms. I am able bind values from the List<> to Picker using XAML. There are two pickers in my Registration Form. The requirement is that depending on the selection of item from the first Picker, I want to add items in the second picker. Is this possible? Any help would be appreciated!

EDIT: Example
In first picker, I have A, B, C, D.
If user selects A, then second picker must display A1, A2, A3.
If user selects B, then second picker must display B1, B2, B3.
If user selects C, then second picker must display C1, C2, C3.
If user selects D, then second picker must display D1, D2, D3.

All the above values A, B, C, D and A1 A2,.... etc will come from list or web API.(no issues with this part. It's working)

How to implement Fused Location Provider in Xamarin Forms?

$
0
0

Hi,
I am stuck in implementing Fused Location Provider (as explained here) to find indoor Geo-Coordinates. At a very first place it gives the following error:

error CS0103: The name 'LocationServices' does not exist in the current context

Can you please help with this error or any other suggestion for getting the indoor locations using Xamari.Forms? Thanks


RSA Encryption

$
0
0

Hi,

Please help me to encrypt string(password) in Xamarin using RSA algorithm. I am using following code in Android native. Please help me to port this in Xamarin,

        byte[] keyBytes = Base64.decode(key.getBytes("utf-8"), Base64.DEFAULT);

        X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey publicKey = keyFactory.generatePublic(spec);

        Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] encryptedBytes = cipher.doFinal(plain.getBytes());
        encrypted = Base64.encodeToString(encryptedBytes, Base64.NO_WRAP);

Thanks...

Why is idle HEAP always the same size regardless of maximum available?

$
0
0

After checking my app on multiple Android devices, I've noticed something odd with respect to he available heap space.
One device might have a max of 256. Another a max of 512. If I don't set largeheap to true then it will be 128.
Yet regardless the size of the heap the AVAILABLE heap is always 15mb when idle.
This is not a static value. I can see it rise and fall with work being done. The available being returned seems accurate because if I don't take precautions when scanning and drive it down to <2mb then it will throw an OOM exception stating it tried to allocate 3mb with only 1.4 available-and the amount the exception said was available matches my calculated amount.

So that's where I am confused. How does the same app which presumably has the same base footprint never get more available heap regardless of largeheap or device? More importantly - How can I use that available heap? Its silly that I'm going OOM when I have 512 total and not using any of it.

I tend to beleive these calculations are right because they change correctly when I change devices or turn of LargeHeap; but I'll provide them anyway in case someone knows a better way.

//This is running from the Droid project and returning the value to the PCL

        /// <summary>Return in MB
        /// 
        /// </summary>
        /// <returns></returns>
        public override decimal GetTotalHeap()
        {
            Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime();
            long maxHeapSizeInMB = runtime.MaxMemory() / 1048576L;
            return maxHeapSizeInMB;
        }

        public override decimal GetAvailHeap()
        {
            Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime();
            var aval = runtime.FreeMemory();
            return aval / 1048576L;
        }

Select an item is MasterDetail page by default

$
0
0

Hi,

I have just created a new MD page in C# by using Visual Studio (so it created the templates for me)
and while I can navigate to different pages by selecting an option on the left, I want the first page shown to the user to be the first item of the list.

How can I do that?

Parts of RelativeLayout not showing with TranslateX

$
0
0

I'm creating a custom ListView that is a StackLayout (list) containing a bunch of RelativeLayouts (the list items). I want to add the ability to swipe the list items to show more options. I need to do this custom because the list items are not uniform at all and the list must look the same on iOS and Android.

I have 2 solutions that each have a problem. Here is how I add the extra options to my RelativeLayout. Notice they go beyond the bounds of the RelativeLayout.

{
                            trashLayout,
                            Constraint.RelativeToParent(parent => parent.Width ),
                            Constraint.Constant(0),
                            Constraint.Constant(80),
                            Constraint.Constant(80)

}

First I added the RelativeLayout to a ScrollView and everything shows up fine, the problem is I don't want the user to be able to scroll the list item, I want them to swipe it to show more options (using ScrollToAsync). So is there a way to disable scroll on a ScrollView? I know that sounds silly..

So then I tried removing the ScrollView and just having the RelativeLayout. The swiping works great now, however the overflow of the view (the additional options) are now not showing when I do TranslateTo to the view, as can be seen in the pic.

How do I get the entire view to render so using TranslateTo will show the options? Or how can I disable the scrolling of a ScrollView?

Thanks.

Any tools or libs for displaying an offline map using local vector mbtiles?

$
0
0

Are there any tools or libs for displaying an offline map using local vector mbtiles file stored on device?
(I use mbtiles from openmaptiles.com.)

I've tried tried MapsUI but it only support raster tile.

Any suggestion?

Thanks

Xamarin Forms QR code scanner blank screen

$
0
0

I have a Xamarin Forms 2.0 application that uses ZXing.Net.Mobile and ZXing.Net.Mobile.Forms version 2.0.3.1. I'm trying to build a simple QR code scanner, but whenever I launch the ZXingScannerPage on Android I can see the default overlay (with the text and the red line) but I don't see the output of the camera so I can't actually scan anything. I have already listed the Camera permission in my AndroidManifest:

I tried the sample code from the readme: https://github.com/Redth/ZXing.Net.Mobile as well as from their Samples/Forms project. I now have this code:

`private async void OnScanQrClicked(object sender, EventArgs e)
{
_scannerPage = new ZXingScannerPage();
_scannerPage.OnScanResult += HandleScanResult;

await Navigation.PushAsync(_scannerPage);

}

private void HandleScanResult(Result result)
{
_scannerPage.IsScanning = false;

Device.BeginInvokeOnMainThread(() =>
{
    Navigation.PopAsync();
    DisplayAlert("Scanned code", result.Text, "OK");
});

}`

Some more specs: I'm running Android 5.1 on a Moto G (v1).

Why am I not seeing the output of the camera?

Is there a Clipboard plug-in/component for Xamarin.Forms?

$
0
0

I need to implement Copy to Clipboard within my app. Is there a component/plug-in to support this, or am I back to writing more DependencyServices?

Thanks,

John H.


Accessing Phone contacts and send sms

$
0
0

What's the best way to access the phonebook and send sms to a contact on Xamarin.Forms. Is there any good package or plugin fro Xamarin.Forms I can use to accomplish this task? Keep in mind I want it to be cross-platform. Thank you in advance for the replies.

Trouble with Binding Can get but can't set

$
0
0

Hi guys,

I am new to XF and just trying to learn Binding a bit.

In my XAML, I have the following label:

<Label HorizontalOptions="Center" VerticalOptions="Center" Grid.Column="0" Grid.ColumnSpan="3" Text="{Binding Credit}" />

and in the code behind, I have the following:

              private string credit { get; set; } 
              public string Credit  {
                        get
                        {
                            return credit; 

                        }
                        set
                        {
                            credit = value;
                    }
                             }

So when I set an initial value, for example, credit = "0.00" it works perfectly fine but my problem is setting it:

   private void Button_OnClicked(object sender, EventArgs e)
        {
        var crdString = Credit;

            float crd = float.Parse(crdString);
            crd++;
            credit = crd.ToString();
        }

But it does not update the UI.

P.S I have also set the BindingContext :

        InitializeComponent ();
            BindingContext = this;

xam.plugin.media not working on Android (Works on UWP)

$
0
0

xam.plugin.media not working on Android (Works on UWP)

I've started xamarin forms recently and have been trying to get xam.plugin.media to work. I scoured the web and am at the end of my wisdom.

I'm checking if I have permissions, a camera is available, photo is supported and even then it crashes.
Plugins were implemented as stated by the readme and/or fellowbloggers.
Permissions set in my xamarin liveplayer device.

Even tried example solutions but since they are usually out of date and xamarin aswell as the plugin doesnt quite like that they didnt work aswell.

Solution github.com/peyter213/xam_plugin_media-Issue

Thanks to anyone that dares to take a look.

Error: i.imgur.com/GrarxPq.png

Codeexample of the MainPage

MainPage.xaml.cs
` private async void Btn_takePhoto_Clicked(object sender, EventArgs e)
{
try
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
if (status != PermissionStatus.Granted)
{
if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Camera))
{
await DisplayAlert("Camera Permission", "Allow SavR to access your camera", "OK");
}

                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera });
                status = results[Permission.Camera];
            }

            if (status == PermissionStatus.Granted)
            {

                await CrossMedia.Current.Initialize();

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera available.", "OK");
                    return;
                }
                var s = CrossMedia.Current.IsCameraAvailable;
                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    PhotoSize = PhotoSize.Medium,

                });

                if (file == null)
                    return;
            }
            else if (status != PermissionStatus.Unknown)
            {
                await DisplayAlert("Camera Denied", "Can not continue, try again.", "OK");
            }
        }
        catch (Exception ex)
        {

            await DisplayAlert("Error", "Camera Not Available", "OK");
        }
    }`

How to use ClassId

$
0
0

Hi,
I'm trying to do an alternative ListView where I want to be able to change and update labels after the "cells" are created. This is my first test, just put alot of stacklayouts in a scrollview. The problem is that I cant figure out how to change the ".Text" parameter for the labels based on their ClassIds.
This simple test should work as that if I click on for example the button with the ClassId "1" the Text of the Label with the ClassId "lbl1" should change to "Hello". So I guess the main question is how to reference an item based on it's ClassId? Hope this makes some sense..

Best regards
Magnus

using System;
using Xamarin.Forms;

namespace TestScroll2
{
    public partial class TestScroll2Page : ContentPage
    {
        StackLayout mainLayout;
        public TestScroll2Page()
        {
            mainLayout = new StackLayout
            {
                Margin = new Thickness(0, 0, 0, 0)
            };

            for (var i = 0; i < 40; i++)
            {
                var stackLayout = new StackLayout();
                stackLayout.ClassId = "Stack" + i;

                var stackLabel = new Label()
                {
                    Text = "Separators in stack layout " + i
                };
                stackLabel.ClassId = "lbl"+i;
                var stackButton = new Button()
                {
                    Text="Click Me"
                };
                stackButton.ClassId=""+i;
                stackButton.Clicked += OnButtonClicked;

                stackLayout.Children.Add(stackLabel);
                stackLayout.Children.Add(stackButton);

                stackLayout.BackgroundColor = Color.Gray.MultiplyAlpha(0.2);

                mainLayout.Children.Add(stackLayout);
            }

            Content = new ScrollView() { 
                Margin = new Thickness(0, 30, 0, 0),
                Content = mainLayout 
            };
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            StackLayout stl = (StackLayout)btn.Parent;
            DisplayAlert("Alert", "OnButtonClicked: "+btn.Parent.ClassId , "OK"); // this works
            //this.FindByName<Label>("lbl1").Text="Hello"; -> this is where I like to update the corresponding label
        }
    }
}

missing templates in visual studio

$
0
0

hi,
i have visual studio enterprise 2017 and i installed all the things to be worked with xamarin.
i did it maybe 5 times in two weeks and im getting crazy.
when i choose in visual studio file->new->project, i choose in the left pannel for c#, cross platform

i have only two options:
1)UI Test APP
2)class library(xamarin forms)

everyone i know include posts at the internet have a third option:
3)Cross platform App(xamarin forms or native)

which is the exactly i need!

when i choose the second option i can choose between shared project or .net standard. this thing its only in my computer
everyone else has portable class instead of the .net standard option and i need the poratable!

what do i need to install to have the third options?
i've been trying to seek for this two weeks

please help!!!

Viewing all 58056 articles
Browse latest View live


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