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

Native Linking Error on iOS Binding library

$
0
0

I'm not quite sure how to troubleshoot this and was hoping for some insights. I've got a Xamarin Forms solution that uses an iOS binding library I created from a 3rd party. I got new files and was able to bind it and create a dll. The only thing different was this time I had to use Xcode 9.4.1. When I brought the dll back into my xamarin forms solution I get the errors below by running against an iOS simulator with the following Additional mtouch arguments
--registrar:static --gcc_flags -stdlib=libc++ -v -v -v -v

In the iOS binding library my native reference libMyChart.a has the following settings:
Force Load: True

Frameworks: WebKit HealthKit CoreGraphics Foundation UIKit CoreLocation MediaPlayer SystemConfiguration MobileCoreServices QuartzCore EventKitUI EventKit OpenGLES AudioToolbox CoreVideo CoreMedia AVFoundation Security CoreText CFNetwork

Linker Flags: -ObjC -lstdc++ -lxml2

Smart Link: True

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(786,3): error : Native linking error: framework not found /Users/dwighthyde/Library/Caches/Xamarin/mtbs/builds/UCH.MHC.Mobile.iOS/36e1d1f4518f8e9cd999de204f2e866f/obj/iPhoneSimulator/Debug/mtouch-cache/x86_64/registrar.o
1> C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(786,3): error : Native linking failed. Please review the build log and the user flags provided to gcc: -stdlib=libc++ -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/dwighthyde/Library/Caches/Xamarin/mtbs/builds/UCH.MHC.Mobile.iOS/36e1d1f4518f8e9cd999de204f2e866f/obj/iPhoneSimulator/Debug/Entitlements.xcent
1> C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(786,3): error : Native linking failed. Please review the build log.


How can I open a local PDF on Xamarin Forms?

$
0
0

Lets say I saved a PDF file to my local project. How can I have a button in Xamarin Forms open the PDF in the devices default viewer? How would I be able to open it in a web browser?

  • I tried opening it in URI with the file path, but that doesn't seem to work.
  • I dont want to make a custom PDF webview, I just want it to open in some default viewer or browser if possible.
  • Opening the pdf file path in Android PrintDocumentAdapter pda = new CustomPrintDocumentAdapter(filePath); seems to work, but this is some print preview view
  • Opening it in UWP with Windows.System.Launcher.LaunchFileAsync(file); seems to work great. Why doesn't Android and iOS have something like this?

using scrollview with grid

$
0
0

how can use scrollview for this code?

<StackLayout>
    <RelativeLayout>
        <Grid BackgroundColor="White" RowSpacing="1" >
            <Grid.RowDefinitions>
                <RowDefinition Height="7*" />
                <RowDefinition Height="3*" />
                <RowDefinition Height="3*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="2*" />
                <ColumnDefinition Width="1*" />

            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0" Grid.Row="0" RowSpacing="1"  >
                <imb:ImageButton  Source="@Resources/" />
            </Grid>
            <Grid Grid.Column="1" Grid.Row="0"  RowSpacing="1" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="2*" />

                </Grid.RowDefinitions>
                <imb:ImageButton   Grid.Row="0" 
                   Source="@Resources/u.jpg"       />
                <imb:ImageButton  Grid.Row="1" 
                                  Source="@Resources/u.jpg" />

            </Grid>
            <Grid Grid.Row="1" Grid.Column="0" RowSpacing="1"   >
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="1*" />
                </Grid.RowDefinitions>

                <imb:ImageButton   BackgroundColor="Gold"  Grid.Row="0" />
                <imb:ImageButton   BackgroundColor="Gainsboro"  Grid.Row="1"  />
            </Grid>
            <Grid Grid.Row="1" Grid.Column="1" RowSpacing="1" >

                <imb:ImageButton  BackgroundColor="Aqua" />

            </Grid>
            <Grid Grid.Row="2" Grid.Column="0" RowSpacing="1" >

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <imb:ImageButton    Grid.Column="0"  BackgroundColor="BlueViolet"  />

                <imb:ImageButton    BackgroundColor="AliceBlue"  />
            </Grid>
            <Grid Grid.Row="2" Grid.Column="1" RowSpacing="1" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="1*" />
                    <RowDefinition Height="1*" />
                </Grid.RowDefinitions>
                <imb:ImageButton  BackgroundColor="Beige"  Grid.Row="0" />
                <imb:ImageButton  BackgroundColor="Bisque"  Grid.Row="1" />
            </Grid>
        </Grid>
    </RelativeLayout>

    <RelativeLayout  >
        <Grid  RowSpacing="1" >
            <Grid.RowDefinitions>
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>
            <imb:ImageButton Grid.Row="0" BackgroundColor="Orange" />
        </Grid>
    </RelativeLayout>

</StackLayout>

Custom sound from FCM Notification?

$
0
0

Is there any way to play custom sound on notification receive(firebase notification) for both iOS and Android?(even if app is closed).

Playing a notification Sound on Android

$
0
0

I am trying to create a notification and play a sound. the following code mostly works.

NotificationManager notificationManager = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService);
Notification.Builder builder = new Notification.Builder(Android.App.Application.Context);
builder.SetSound(uri);

builder.SetAutoCancel(true);
builder.SetContentTitle(action);
builder.SetContentText(body);
builder.SetSmallIcon(Resource.Drawable.ACLogo);
builder.SetDefaults(vibrate ? NotificationDefaults.All : NotificationDefaults.Sound);
builder.SetOngoing(false);

notificationManager.Notify(1010, builder.Build());

I am pulling the uri from one out of the list of ringtones on the device. This has several issues.

1st, builder.SetSound(uri) is deprecated. All forms of it seem to be, so what is the replacement for it?
2nd, build.SetDefaults(...) is also deprecated.
3rd, if I issue build.SetDefaults, then it does not play the sound I am setting.
4th, if I don't issue build.SetDefaults, it plays the correct sound, but keeps playing it over and over.

I only want the sound to play one time. It is supposed to be more like an alert sound, like when a text message shows up, not like the phone ringing until you answer it.

I can't seem to find answers to how to actually make this work. Even when I was just trying to play a sound instead of create a notification, I didn't really see what the answer was to how ringtone.Play() can be limited to only once instead of looping until ringtone.Stop() is issued.

Section Index feature in Xamarin Forms

$
0
0

Hello everyone

Is there a way to create a "Section Index" (Xamarin Android feature) in a Listview using Xamarin Forms? I´ve been searching for a while without result except for this one https://github.com/xamarin/Xamarin.Forms/issues/1481 but testing that example it does not showing the bubble on my Android emulation (Oreo).

Any help is welcome.

Thanks

Best way to iterate through a selection of Xamarin.Forms controls?

$
0
0

Does anyone know a better way to loop through the children of than this:

        void OnSliderValueChanged(object sender, ValueChangedEventArgs args)
        {
            double value = args.NewValue;
            foreach (Label label in A.Children)
            {
                label.HeightRequest = value;
                label.WidthRequest = (value * 4);
                label.FontSize = value;
            }
        }

Can I assign controls to a "class" as in HTML and then iterate through the class members?
Can I refer to the children without specifying their type and just iterate by ordinal position, as in A.Children(5).HeightRequest = value; ?

3D Carousel?

$
0
0

Hello everyone!

Curious if there are any projects out there that show a carousel with the active item as larger than the two items on either side, and animate larger as the focused item is dragged into the foreground, or even tapped.


University Course XAM130 Step 19 Add a name to the XAML Label

$
0
0

I have an unresolvable error at this step,
"Error CS1061 'MainPage' does not contain a definition for 'resultText' and no accessible extension method 'resultText' accepting a first argument of type 'MainPage' could be found (are you missing a using directive or an assembly reference?)"
My XAML follows:

<Label x:Name="resultText" FontAttributes="Bold" FontSize="48" BackgroundColor="Black" Text="0" TextColor="White" 
HorizontalTextAlignment="End" VerticalTextAlignment="Center" LineBreakMode="NoWrap" Grid.ColumnSpan="4" />

Forms9Patch: Simplify multi-device image management in your PCL Xamarin.Forms mobile apps

$
0
0

Announcement of Form9Patch

Xamarin Forms is great for developing apps on Android and iOS but it is missing two important tools for developers: scalable images and PCL multi-screen image management. Android developers use NinePatch bitmaps and the drawable directory naming convention for this purpose. Likewise, iOS developers use ResizeableImageWithCapInsets and the @2x, @3x, @4x file naming convention for this purpose.

Forms 9 Patch enhances Xamarin Forms to enable multi-resolution / multi-screen image management to PCL apps for iOS and Android.

What is it?

Simply stated, Forms9Patch is two separate elements (Image and ImageSource) which are multi-screen / multi-resolution extensions of their Xamarin Forms counterparts.

Forms9Patch.ImageSource

Xamarin Forms provides native iOS and Android multi-screen image management (described here). This requires storing your iOS images using the native iOS schema and storing your Android images using the Android schema. In other words, duplicative efforts to get the same results on both Android and iOS. Forms9Patch.ImageSource extends Xamarin.Forms.ImageSource capabilities to bring multi-screen image management to your PCL assemblies - so you only have to generate and configure your app's image resources once. Forms9Patch.ImageSource is a cross-platform implementation to sourcing multi-screen images in Xamarin Forms PCL apps as embedded resources.

Forms9Patch.Image

Forms9Patch.Image compliments Xamarin.Forms.Image to provide Xamarin Forms with a scaleable image element. Scalable images are images that fill their parent view by stretching in designated regions. The source image for the Forms9Patch.Image element can be specified either as a Forms9Patch.ImageSource or a Xamarin.Forms.ImageSource. Supported file formats are NinePatch (.9.png), .png, .jpg, .jpeg, .gif, .bmp, and .bmpf.

Example code

After adding the file bubble.9.png to your PCL project assembly as an EmbeddedResource, you can display it using something like the following:

var bubbleImage = new Forms9Patch.Image () {
    Source = ImageSource.FromResource("MyDemoApp.Resources.bubble.9.png"),
    HeightRequest = 110,
}
var label = new label () {
    Text = "Forms9Path NinePatch Image",
    HorizontalOptions = LayoutOptions.Center,
}

Example XAML

In Xamarin Forms, access to embedded resources from XAML requires some additional work. Unfortunately, Forms9Patch is no different. As with Xamarin Forms, you will need (in the same assembly as your embedded resource images) a simple custom XAML markup extension to load images using their ResourceID.

    [ContentProperty ("Source")]
    public class ImageMultiResourceExtension : IMarkupExtension
    {
        public string Source { get; set; }

        public object ProvideValue (IServiceProvider serviceProvider)
        {
            if (Source == null)
                return null;

            // Do your translation lookup here, using whatever method you require
            var imageSource = Forms9Patch.ImageSource.FromMultiResource(Source);

            return imageSource;
        }
    }

Once you have the above, you can load your embedded resource images as shown in the below example. Be sure to add a namespace for the assembly that contains both your MarkupExtension and your EmbeddedResources (local in the below example).

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:MyXamlDemo;assembly=MyXamlDemo"
    x:Class="MyXamlDemo.MyPage"
    Padding="5, 20, 5, 5">
    <ScrollView>
        <ScrollView.Content>
            <StackLayout>
            <Label Text="Xamarin.Image"/>
            <Image Source="{local:ImageMultiResource Forms9PatchDemo.Resources.image}"/>
            </StackLayout>
        </ScrollView.Content>
    </ScrollView>
</ContentPage>

Where to learn more

Project page: http://Forms9Patch.com
Nuget page: https://www.nuget.org/packages/Forms9Patch/0.9.1
Demo app repository: https://github.com/baskren/Forms9PatchDemo

Assigning an id to a listview item and getting that id when that list item was tapped.

$
0
0

I am populating my list view with data I get from a JSON call. I get a name and a corresponding id. I populate the list view with the names as follows.

listView.ItemTemplate.SetBinding(TextCell.TextProperty, "Name");

Now What I want to do with the id is something like

listView.ItemTemplate.SetBinding(TextCell.Id, "NameId");

where the id is hidden from the user.

And do something like the following when an item is clicked get the id

listView.ItemTapped += (sender, e) => {

                System.Diagnostics.Debug.WriteLine(e.item.Id );

            };

Any ideas on how I can accomplish this?``

Camera access with the media plugin

$
0
0

Hi,

I do my first steps in Xamarin Forms following a Udemy course.
In order to access the the phone camera I was getting some ideas from a youtube tutorial using
the media plugin. After pressing a button a photo shout be shot.

When deploying the code on the my phone via Visual Studio 2017 and the live player
I get the message "The method or operation is not implemented".

The plugin is installed and no errors are present in the editor window.

Can someone point me to a possible error?
The line the gives the error is indicated in the code-behind file.

Thanks in advance,
Tim

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="xxx://xamarin.com/schemas/2014/forms"
             xmlns:x="xxx://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:PhotoApp01"
             x:Class="PhotoApp01.MainPage">

    <StackLayout>
        <Button x:Name="TakePictureButton"
                Clicked="TakePictureButton_Clicked" 
                Text="Take from Camera"/>
        <Button x:Name="UploadPictureButton"
                Clicked="UploadPictureButton_Clicked"
                Text="Pick a photo"/>
        <Image x:Name="Image1" HeightRequest="240" />
    </StackLayout>
</ContentPage>




        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using Plugin.Media;
        using Plugin.Media.Abstractions;
        using Xamarin.Forms;

        namespace PhotoApp01
        {
            public partial class MainPage : ContentPage
            {
                public MainPage()
                {
                    InitializeComponent();
                }

                private async void TakePictureButton_Clicked(object sender, EventArgs e)
                {
                    await CrossMedia.Current.Initialize();

                    if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                    {
                        await DisplayAlert("No camera", "No camera available", "OK");
                        return;
                    }

        ///////////////////////////////////////////////////////
                    // THE NEXT LINE CAUSES THE ERROR MESSAGE
        ///////////////////////////////////////////////////////            

                    var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        SaveToAlbum = true,
                        Name = "test.jpg"
                    });

                    if (file == null)
                        return;

                    Image1.Source = ImageSource.FromStream(() => file.GetStream());

                }

                private async void UploadPictureButton_Clicked(object sender, EventArgs e)
                {
                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        await DisplayAlert("No camera", "No camera available", "OK");
                        return;
                    }

                    var file = await CrossMedia.Current.PickPhotoAsync();

                    if (file == null)
                        return;

                    Image1.Source = ImageSource.FromStream(() => file.GetStream());

                }                        
            }
        }

How to draw using real sizes on Xamarin.Forms using SkiaSharp?

$
0
0

Hi. My goal is to draw a line in a fixed size in millimeters
I have tried to achieve this by converting from mm to dp. I'm using this formula:

private void canvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
    SKSurface surface = e.Surface;
    SKCanvas canvas = surface.Canvas;
    canvas.Clear(SKColors.CornflowerBlue);

    int width = e.Info.Width;

    //Set transforms
    canvas.Translate(width / 2, 30);




    // In milimeters
    float heightInMilimeters = 10f;

    // In pixels. 
    // Constants.PIXELS_IN_MILIMETER = 3.779527559f
    var heightInPixels = heightInMilimeters * Constants.PIXELS_IN_MILIMETER;

    // In dp
    //dp = px / (dpi / 160)

    // heightInPixels = 37.79527559
    var heightInDeviceUnit = heightInPixels / 1.5   // Device with hdpi

    // heightInDeviceUnit = 25.19685039333333
    var rect = SKRect.Create(widthInDeviceUnit, heightInDeviceUnit);
    canvas.DrawRect(rect, blackFillPAint);
}

But when I measure the rectangle with a ruler it is not 10mm height.

I'm not sure if the way I went is the right way and if I missing something at the road.
Any help will be apreciated.
Thanks

Focusing on Entry Field Each Time a ContentView View Shows

$
0
0

I have MyView.xaml.cs and MyView.xaml (which is a ContentView) defining MyView view.

MyView has an Entry field. How do I focus on that Entry field each time MyView is shown on screen?

Originally, I thought I could just to to MyView.xaml.cs and override OnAppearing() lifecycle method. But ContentView does not have OnAppearing().

set custom font in webview

$
0
0

I want to set my own custom font in webview.

WebView Description = new WebView(this.Context); WebSettings settings = Description.Settings; settings.FixedFontFamily = "DIN-Condensed-Bold.ttf";

I have added my Font called DIN-Condensed-Bold.ttf in Assets/fonts folder, but I don`t see the effect.
Is it build action problem? How can I implement it?


Browser support plans?

$
0
0

Hi, the company I work for is considering different C# based solutions for a industry focused product re-write that has a VERY strong desktop user interface (touches many Win32 features) and a VERY strong web portal user interface (many cloud based features). In short we would like to go with a singular UI that spans both the browser and desktop side. HTML/JS/TS are not good options as they're not fully type-safe and thus make refactoring core logic and UI a nightmare (runtime errors are not productive development methods). XAML/C# are miles ahead for writing productive applications that have both high and low level parts mitigating complexity when maintaining large applications. The big missing feature is XAML in the browser!

This project will start late 2018 or early 2019. I'm fishing for options here as the UI changes how a lot of stuff can be done in the project.

--- I've see this (Ooui): https://github.com/xamarin/Xamarin.Forms/issues/1895
1) In short will Xamarin.Forms support the browser/HTML5?
2) If so any known timelines for when this might be?

How can I allow only my Xamarin App to access Easy Table and Easy API?

$
0
0

Hi,

I'm a newbie with Xamarin but have done C# programming in the past, I'm currently using Azure's Easy Table and soon Easy API. To increase security, I'd like to prevent other apps from accessing my Easy Tables and Easy APIs. I have set up my Easy Tables to "Allow anonymous access" right now, I believe I should set this to "Authenticated" to prevent other apps in accessing my Easy Tables and APIs.

So should I create one account maybe in Active Directory and use it in my app in the authentication process to only allow my app to access my Easy Tables and APIs?

Should I add an "ID" in my app and have the back end filter other requests that doesn't have the "ID"? And if so, how does one go about it? Should I modify the Node.JS script? How secure can this be?

Note, I have my own user authentication based on user email address and password and it is working okay, but this is on an application level authentication only(i.e., if users provides correct email address and password, they are able to order, view history, etc.). This obviously will not prevent other apps in accessing my Easy Tables and Easy APIs.

Thanks everyone!

How do you implement a filter on a listView?

$
0
0

Hi guys,

So here is the current situation: I have a ListView on a page full of ListView items (like price, sort of product etc) and I have another page where I designed a filter on it (filter by price, sort of product). My question is how can I make the filter function on the listView? How do I have to approach this?

Please help me out.

Environment.SpecialFolder.Personal is a good place to store photos in my app?

$
0
0

I use this code in IOS

var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

but it seems that the photos are deleted every time I update the app, is there another directory more appropiate?

IsPullToRefreshEnabled not available

$
0
0

IsPullToRefreshEnabled is not available when it is full. But if you remove InitializePage (); in MainPage, then everything works as it should.

xaml:
ListView x:Name="TasksView"
IsPullToRefreshEnabled="True"
RowHeight="89"
Margin="2,4"
ItemTapped="SelectItem">

cs:
public MyTasks ()
{
InitializeComponent ();
InitializePage();
TasksView.RefreshCommand = new Command(() => {
InitializePage();
TasksView.IsRefreshing = false;
});
}
protected void InitializePage()
{
TasksView.ItemsSource = TaskController.GetMyTasks(); ;
}

Viewing all 77050 articles
Browse latest View live


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