Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

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


Navigation drawer and tab together

$
0
0

I tried to design a page which hold navigation drawer and tab together with some content in xamarin using visual studio, am getting navigation drawer as well as tabs on individual solution.How to make it together on a single page in a solution.

How to add line breaks in a label in Xamarin Forms using XAML

$
0
0

I am trying to add line breaks to a label in Xamarin Forms using XAML, but it doesn't seem to work. This is the code I have right now that doesn't work:

<Label Text="All my text goes here etc\r\nawljfal alwef law fawlef lwemfalwfem" TextColor="White" WidthRequest="100" />

The '\r\n' actually outputs in the label text.

enable Location using OnProviderDisabled

$
0
0

Hi All,

straight to the point i have application that check if gps enabled if not it will ask the user to go to settings and enable it but i am getting exception :
Unhandled Exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. occurred

MainPage.xaml.cs :

    protected override void OnAppearing()
            {
                btnShowMap.IsVisible = false;
                DependencyService.Get<ILocation>().LocationChanged += OnLocationChanged;
                DependencyService.Get<ILocation>().ProviderDisabled += OnProviderDisabled;

                txtFollower.Text = DependencyService.Get<IMyMobileNumber>().getMyNumber();
                base.OnAppearing();
            }

in android project :
i have class with constructor

public mobLocation()
        {
            lm =Forms.Context.GetSystemService(Context.LocationService) as LocationManager;


            if (lm.IsProviderEnabled(LocationManager.GpsProvider))
            {
                lm.RequestLocationUpdates(LocationManager.GpsProvider, 3000, 100, this);
            }
            else
            {
                LocationChanged = null;
                ProviderDisabled(this, null);
                Log.Info("GPS OFF", "gps isnot running");
            }
        }

when i run the application i get

Pre-release: Xamarin.Forms 2.3.5.256-pre6

$
0
0

We've pushed Xamarin.Forms 2.3.5.256-pre6 to NuGet and have begun QA in preparation for making this our next stable release.

To install the pre-release, check the pre-release option in your NuGet manager and install this version.

For some quick highlights, check out our blog announcement. Hint: Fast Renders for Android, ListView performance enhancements and fixes, and MacOS preview.

If you’ve got a bug to report, drop us a quick report here so we can troubleshoot in detail.

As you have performance specific feedback, please join the discussion in this performance specific thread.

Important notes

  • Xamarin.Forms is now compatible with .NET Standard projects! Not all build features may work.
  • Behavior change: Device.RuntimePlatform now returns WinRT on WinRT and UWP on UWP.
  • Behavior change: Using the new AutomationProperties may impact UI Test execution on Android. AutomationId, Name, and HelpText will all set the native ContentDescription property, with Name and/or HelpText taking precedence over AutomationId (Name and HelpText will be concatenated). This means that any tests looking for AutomationId will now fail if Name and/or HelpText are also set on that element. To work around this issue, please alter your UI Tests to look for the value of Name/HelpText in this scenario.
  • Behavior change: Calling Focus on a Picker on WinRT/UWP will now open the drop down.
  • Deprecation: Android IVisualElementRenderer.ViewGroup is now obsolete. Please use View instead.

2.3.5.256-pre6

  • 56795 - "DataTriggers do not work on UWP in RELEASE mode"

2.3.5.255-pre5

  • [Android] Dispose check before setting properties on Button (PR)
  • 36031 - "Button border not drawn on Android without a BorderRadius" (PR)
  • 57717 - "Setting background color on Button in Android FormsApplicationActivity causes NRE" (PR)
  • 57749 - "[UWP] After enabling a disabled button it is not clickable" (PR)
  • [Android] Dispose check on FastButtonRenderer to prevent crash (PR)
  • [Android] Set the Id field for Android Views created by Forms (PR)
  • 55588 - "Cannot open more than one ContextAction in different ListViews on IOS" (PR)
  • 56444 - "A small "dot" shows up as value in Android labels when the value is null/empty." (PR)
  • 56895 - "VS2017 stable - previewer exception crash- no method found Button_click on type" (PR)
  • 56896 - "ListViews for lists with many elements regressed in performance on iOS" (PR)
  • 57108 - "Fix possible crash on API 21+ at launch when using Holo theme and FormsApplicationActivity" (PR)

Release Notes

2.5.3.239-pre3

Release Notes

2.3.5.235-pre2

Release Notes

2.3.5.233-pre1

Release Notes

Scroll down Menu at the top

$
0
0

In Mobile at the Top 3 line menu when clicked displays menu but it touches the top. So, in order to show it down I had used Header at the Top, like as explained in https://forums.xamarin.com/discussion/35913/listview-header-and-footer
I had used it in .cs like:
BindingContext = IdentityHelper.Users.UserName;
listView.SetBinding (ListView.HeaderProperty, new Binding("."));

Now, it's displaying Logged in User Name at the Top.The only problem is I want to set Background & Textcolor of Header ? How can that be done?

Visual studio stops debugging android application

$
0
0

I'm using visual studio 7.0.1 (build 24) for my mac. have simple android project. while debugging visual studio suddenly stops debugging process. What I found in log s is on error (Ide...log)

ERROR [2017-07-06 15:21:35Z]: Inspector is not supported on physical Android devices

Key board hiding the text field, not able to scroll the view.

$
0
0

Zip.AccessibilityScroll(UIAccessibilityScrollDirection.Up);
Tried the above code.


how to set up an application

$
0
0

I am following this example but it is not that useful:
https://github.com/xamarin/urho-samples/tree/master/FeatureSamples/Core/29_SoundSynthesis

anyhow I am getting an run time error that says: The application is not configured yet.
but I made an application object .
the error happen a node = new Node();
what am I missing
this is my class:

using System;
using Urho.Audio;
using Urho;
using Urho.Resources;
using Urho.Gui;
using System.Diagnostics;
using System.Globalization;
namespace Brain_Entrainment
{
public class IsochronicTones : Urho.Application
{
/// Scene node for the sound component.
Node node;

/// Sound stream that we update.
BufferedSoundStream soundStream;
public double Frequency { get; set; }
public double Beat { get; set; }
public double Amplitude { get; set; }
public float Bufferlength { get; set; }
const int numBuffers = 3;

//protected IsochronicTones(ApplicationOptions options = null) : base(options) {}

public IsochronicTones(ApplicationOptions AppOption) : base (AppOption)
{
    Amplitude = 1;
    Frequency = 100;
    Beat = 0;
    Bufferlength = Int32.MaxValue;

}

public void play()
{
    Start();


}

protected override void OnUpdate(float timeStep)
{
UpdateSound();
base.OnUpdate(timeStep);

}
protected override void Start()
{
    base.Start();
    CreateSound();
}

void CreateSound()
{
// Sound source needs a node so that it is considered enabled
node = new Node();

SoundSource source = node.CreateComponent();

soundStream = new BufferedSoundStream();
// Set format: 44100 Hz, sixteen bit, mono
soundStream.SetFormat(44100, true, false);

    // Start playback. We don't have data in the stream yet, but the SoundSource will wait until there is data,
    // as the stream is by default in the "don't stop at end" mode
    source.Play(soundStream);
}

void UpdateSound()
{
// Try to keep 1/10 seconds of sound in the buffer, to avoid both dropouts and unnecessary latency
float targetLength = 1.0f / 10.0f;
float requiredLength = targetLength - Bufferlength;//soundStream.BufferLength;
float w = 0;

if (requiredLength < 0.0f)
return;
uint numSamples = (uint)(soundStream.Frequency * requiredLength);
if (numSamples == 0)
return;
// Allocate a new buffer and fill it with a simple two-oscillator algorithm. The sound is over-amplified
// (distorted), clamped to the 16-bit range, and finally lowpass-filtered according to the coefficient
var newData = new short[numSamples];
for (int i = 0; i < numSamples; ++i)
{
float newValue =0;
if (Beat == 0)
{
newValue = (float)(Amplitude * Math.Sin(Math.PI * Frequency * i / 44100D));
}
else
{
w = (float)(1D * Math.Sin(i * Math.PI * Beat / 44100D));
if (w < 0)
{
w = 0;
}
newValue = (float)(Amplitude * Math.Sin(Math.PI * Frequency * i / 44100D));
}
//accumulator = MathHelper.Lerp(accumulator, newValue, filter);
newData[i] = (short)newValue;
}

// Queue buffer to the stream for playback
soundStream.AddData(newData, 0, newData.Length);
}
}
}

how to set up an application

$
0
0

I am following this example but it is not that useful:
https://github.com/xamarin/urho-samples/tree/master/FeatureSamples/Core/29_SoundSynthesis

anyhow I am getting an run time error that says: The application is not configured yet.
but I made an application object .
the error happen a node = new Node();
what am I missing
this is my class:

using System;
using Urho.Audio;
using Urho;
using Urho.Resources;
using Urho.Gui;
using System.Diagnostics;
using System.Globalization;

namespace Brain_Entrainment
{
public class IsochronicTones : Urho.Application
{
/// Scene node for the sound component.
Node node;

/// Sound stream that we update.
BufferedSoundStream soundStream;
public double Frequency { get; set; }
public double Beat { get; set; }
public double Amplitude { get; set; }
public float Bufferlength { get; set; }
const int numBuffers = 3;

//protected IsochronicTones(ApplicationOptions options = null) : base(options) {}

    public IsochronicTones(ApplicationOptions AppOption) : base (AppOption)
    {
        Amplitude = 1;
        Frequency = 100;
        Beat = 0;
        Bufferlength = Int32.MaxValue;

    }

    public void play()
    {
        Start();


    }

protected override void OnUpdate(float timeStep)
{
UpdateSound();
base.OnUpdate(timeStep);

    }
    protected override void Start()
    {
        base.Start();
        CreateSound();
    }

void CreateSound()
{
// Sound source needs a node so that it is considered enabled
node = new Node();

SoundSource source = node.CreateComponent<SoundSource>();

soundStream = new BufferedSoundStream();
// Set format: 44100 Hz, sixteen bit, mono
soundStream.SetFormat(44100, true, false);

        // Start playback. We don't have data in the stream yet, but the SoundSource will wait until there is data,
        // as the stream is by default in the "don't stop at end" mode
        source.Play(soundStream);
    }

 void UpdateSound()
    {
// Try to keep 1/10 seconds of sound in the buffer, to avoid both dropouts and unnecessary latency
float targetLength = 1.0f / 10.0f;
        float requiredLength = targetLength - Bufferlength;//soundStream.BufferLength;
 float w = 0;

if (requiredLength < 0.0f)
    return;
        uint numSamples = (uint)(soundStream.Frequency * requiredLength);
        if (numSamples == 0)
            return;
        // Allocate a new buffer and fill it with a simple two-oscillator algorithm. The sound is over-amplified
        // (distorted), clamped to the 16-bit range, and finally lowpass-filtered according to the coefficient
        var newData = new short[numSamples];
for (int i = 0; i < numSamples; ++i)
{
            float newValue =0;
            if (Beat == 0)
            {
             newValue = (float)(Amplitude * Math.Sin(Math.PI * Frequency * i / 44100D));
            }
            else
            {
                w = (float)(1D * Math.Sin(i * Math.PI * Beat / 44100D));
                if (w < 0)
                {
                    w = 0;
                }
                 newValue = (float)(Amplitude * Math.Sin(Math.PI * Frequency * i / 44100D));
            }
    //accumulator = MathHelper.Lerp(accumulator, newValue, filter);
    newData[i] = (short)newValue;
}

// Queue buffer to the stream for playback
soundStream.AddData(newData, 0, newData.Length);

}
}
}

Xamarin.Firebase.iOS - how to set screen name

Prevent an UIAlertView from closing on PositiveButton click

$
0
0

I am developing mobile application using Xamarin.Forms. I have requirement of getting input in the dialog box. So, i have used UIAlertView for getting text input as like below.

I need to prevent an UIAlertView from closing on button click. I need to retain the UIAlertView dialog box even after the action initiated.

Can anyone please help me on this?

Regards,

Karthik

[0:] Binding: 'Xxx' property not found on 'Yyy', target property: 'Xamarin.Forms.Label.Text'

$
0
0

I keep getting plenty of those error warning in the output console, but every thing shows fine.
Before anyone say it, yes this property is defined on that class and it does display and update correctly.
Yet it prints this warning in the console. Zillion of times. Swamping it with spurious noise.
Anyway to remove those spurious console output?

Migrating an XCode application to VS 2017 for Mac

$
0
0

I wrote a small WatchOS program in XCode prior to the Mac release of VS 2017. I'd like to migrate this XCode app over. There have been some posters asking similar questions, but nothing lately. Is there a method to take an existing XCode (Swift) project and port it over to VS? Note, I am only working in the Mac environment. I'm not expecting an "Easy" button, but are there tools and/or a general process?

Thanks,

Brian

XF native embedding - What is the syntax to tell an Android Fragment to MATCH_PARENT?

$
0
0

Xamarin.Forms PCL project.
ContentPage has an Android Fragment on it using Native Embedding.
I think the fragment is technically working, in that the native engine initialization callback responds with ERROR.NONE, and I can use the API calls that get initialized when the fragment initializes.
The problem is that the fragment has a size of 0,0.

I can set the container size. I cannot for the life of me find any documentation in any of the Xamarin write-ups on how to set the LayoutParameters of the fragment to MATCH_PARENT so it will expand to fit its container.
There's some limited examples of sending x:Arguments, but I'm just guessing in the dark about DataType and parameter casing. The permutations are almost endless.

Per examples: The native MapFragment has been subclassed to "NokiaMapView in order to call Initialize(), create Android Listeners, subscribe to callbacks etc. So NokiaMapView` in the example below is a fragment derived from the native fragment; as shown then the available tutorials.

This is just a small sampling of my attempts. I have a huge amount of commented markup with various combinations and permutations of attempts that all fail at runtime with errors same or similar to the commented error here.

<views:View x:Name="mapWrap"  x:Arguments="{x:Static androidForms:Forms.Context}">
  <androidLocal:NokiaMapView x:Arguments="{x:Static androidForms:Forms.Context}">
    <!--<androidLocal:NokiaMapView.Layoutparameters>
      <x:Arguments>
        <androidForms:Layoutparameters>MATCH_PARENT</androidForms:Layoutparameters>
      </x:Arguments>
    </androidLocal:NokiaMapView.Layoutparameters>-->
  </androidLocal:NokiaMapView>
</views:View>

<!--  06-23 15:04:21.095 I/MonoDroid(23792): Xamarin.Forms.Xaml.XamlParseException: Position 273:25.
      Cannot assign property "LayoutParameters": Property does not exists, or is not assignable, or mismatching type between value and property  -->

@DavidOrtinau @JamesMontemagno @PierceBoggan
You've each written a tutorial or article on behalf of Xamarin for this new ability of embedding native elements in a PCL ContentPage - Do any of you have a technique, example or input on how to set this vital arguement?

~~~~

*Native Embedding references:
https://developer.xamarin.com/guides/xamarin-forms/user-interface/native-views/
https://blog.xamarin.com/adding-bindable-native-views-directly-to-xaml/
https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/add-platform-controls/
https://blog.xamarin.com/unleashed-embedding-xamarin-forms-in-xamarin-native/


How to test an app on an iOS simulator (on a MAC)

$
0
0

I have a solution containing an app for ios, android & windows and I have just added a new UI test project to this solution.
Its built using visual studio 2017 and I can run the ios & android apps on simulators/emulators (my PC is connected to a mac).
My test project is very simple. It contains a reference to my android/ios apps and the test itself pushes a few buttons and takes a screen shot. Simple.

On the PC, I can test my android app on an emulator. But I can't test the ios app - as this is not supported by windows.

On the MAC I also can't test the ios app. The project references (to the ios/android apps) now show errors ie: "Incompatible target framework: Xamarin.ios" or "Incompatible target framework: MonoAndroid".

Can anyone explain what I need to do in order to be able to run the test on my MAC?

Thanks.

Sean

Free Open Source Xamarin Forms UI Library

$
0
0

Xamarin Forms is an amazing set of libraries. Unfortunately, there is a bunch of functionality that is missing. Over time, I've collected bits and pieces of UI components that are necessary for building a modern app and added them to a common .NET Standard/PCL library that can be leveraged on all Xamarin platforms. I didn't write much of the code here, but I have spent a great deal of time making this code more simple, and using tools like Resharper and Code Analysis to improve the code quality as well as building samples of these components. I'm hoping to get others to contribute UI components that will be useful. I will accept all pull requests as long as they add functionality that is missing from the Xamarin Forms components

  • DateTimePicker
  • Camera/Media
  • File Picking
  • Dynamic XAML Rendering
  • GeoLocator
  • WrapLayout

Clone for samples here:
https://github.com/MelbourneDeveloper/Adapt.Presentation.git

Special thanks to @JamesMontemagno as much of the code comes from his original libraries. Unfortunately, those libraries are spread out across multiple repos and NuGet packages. This is good from the perspective that you don't need to add more to your solution than is necessary, so if you only need one component, I recommend looking at his repos. But, I have found that I just end up with dependency spaghetti which leads to all kinds of compilation and runtime errors when I have attempted to add these NuGet packages.

How do I run a xamarin UI test from the command line (on a mac)

$
0
0

From my visual studio project, I can run my test on an ios simulator.
But how do I run this test from the command line?

I thought the answer was nunit-console. But if I use it I get the message "Note: nunit-console shipped with Mono is deprecated, please use the NUnit NuGet package or some other form of acquiring NUnit".

I have no idea what this message means. Can anyone provide some clarity? Is this something which needs to be done from within visual studio for mac?

Thanks, Sean

Setting height of WebView dynamically

$
0
0

Hi,

I have random HTML content coming from service which I am displaying in a webview in a xamarin forms application. Now, I want to adjust the height of this webview as per the content.

Currently I am setting the height based on the length of HTML but it does not give correct results.

Can you suggest an alternate way to achieve the same?

Thanks
Deepesh.

Xamarin Android binding project for an aar obfuscated with DexGuard

$
0
0

Hi all,

We need to do a Binding library project for a aar file obfuscated with DexGuard, but is not generating any class.

The curious thing is that if aar file is obsfuscated with ProGuard, the Xamarin Android Binding project generate correctly the bindings and we are able to use the dll.

I have also checked that the DexGuard aar can be used correctly from a native Android app in Android Studio.

Does someone know if there's an extra step for DexGuard libraries that I'm missing to generate the Bindings? And why Xamarin Android is not able to access the APis if I can use the aar in a native Android application without problems?

Thanks in advance for your help.

Regards

Viewing all 204402 articles
Browse latest View live


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