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


How to hide navigation bar at specific condition without animation in xamarin ios

$
0
0

Hi everyone, I want hide navigation bar at specific condition's. I am using NavigationPage.SetHasNavigationBar is false for hide and set true for visible navigation bar but there is a animation will appear in xamarin ios. I want to remove that animation while hide and show navigation bar. Please suggest any idea.

Confused about paths for images when using Xam.Plugin.Media and cross-platform

$
0
0

I'm using the Media plugin v3.0.1 from James Montemagno for the first time, and I'm quite confused about how it stores and retrieves photos.
Right now I'm questioning the iOS side (I'll worry about Android later).

Here's my basic code:

        async void ShowCamera()
        {
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert(App.alertTitle, ":( No camera available.", "OK");
                return;
            }

            var xFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                SaveToAlbum = true  //,
                //Directory = "Sample",
                //Name = "test.jpg"
            });

            if (xFile == null)
                return;

            Debug.WriteLine("********** NEW PHOTO image:" + xFile);
            //adds pic to grid on the page
            AddPicToGrid(xFile.Path);

            xFile.Dispose();
        }

        async void ShowPhotoPicker(object sender, EventArgs e)
        {
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert(App.alertTitle, ":( Permission not granted to photos.", "OK");
                return;
            }
            var xFile = await CrossMedia.Current.PickPhotoAsync();
            if (xFile == null)
                return;

            Debug.WriteLine("********** PICKED image:" + xFile);
            //adds pic to grid on the page
            AddPicToGrid(xFile.Path);

            xFile.Dispose();
        }

Here are my situations and question:

1) When I call ShowPhotoPicker, and then select an image from my Library, I get a path like this:

/var/mobile/Containers/Data/Application/A1D9636A-1DEE-4E3D-9314-EAD86EA4DC7D/Documents/temp/IMG_20171010_170414.jpg
/var/mobile/Containers/Data/Application/A1D9636A-1DEE-4E3D-9314-EAD86EA4DC7D/Documents/IMG_20171010_170426.jpg

which seems to be dependent upon my app, and specifically, the instance of my app (if I rebuild, the string changes).
When this happens, I cannot reference the same photo from my library anymore because the app string has changed.

2) When I call ShowCamera, after taking a photo, a similar thing happens as in Q1.
While the image is saved into my Library as expected, I can not reference it again if I rebuild my app.

3) I do not want to change and save photos to my app local path - saving/retrieving from the Library is my desired method.

So - How can I reference a photo in my library that is not "app build based" but is instead persistent with a 'fixed' path?

Clearing the navigation stack

$
0
0

Hi,
i am using the prism frame work in xamarin forms. when i am navigating one page to another page all the previous pages adding in to the navigation stack, can any one suggest how can we clear the previous pages from the navigation stack.

Advance Thanks,
Vijay

How fast am I moving?

$
0
0

I need to determine when the phone is moving (e.g.,) more than 5mph. This seems like a daunting task. Any suggestions on where to start?

One (ugly?) approach I have in mind is to get my current location (longitude and latitude?) and then a minute later get it again. Then I'll do the math to figure out how far I've moved and how fast that must be. I'm looking for better ideas. Also, is there a plugin for getting current location?

THANKS!

Firebase RemoteMessageDelegate can't assign "this" in xamarin.ios project on AppDelegate file?

$
0
0

I am using firebase cloud messaging for my xamarin.ios project and I am following this component integration tutorial:
https://components.xamarin.com/gettingstarted/firebaseioscloudmessaging

push notification working great for ios 9 but it doesn't work for ios 10 because I have found two codes doesn't match with my current setting below on my FinishedLaunching method:

UNUserNotificationCenter.Current.Delegate = this;
Messaging.SharedInstance.RemoteMessageDelegate = this;

after finding an enhancement from xamarin official site here https://developer.xamarin.com/guides/ios/platform_features/introduction-to-ios10/user-notifications/enhanced-user-notifications/ I have updated my code for this code below:

from
UNUserNotificationCenter.Current.Delegate = this;
to
UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();

I am still facing the problem with this code : Messaging.SharedInstance.RemoteMessageDelegate = this;
do you have any idea what should be the enhancement for this above single code?

Is possible to put button into sfdatagrid(per line)

Android Emulator fails to execute and doesn't start

$
0
0

Hi,

It's pretty weird but since like 2 weeks, I can't start my android emulator Android_Accelerated_x86.

Starting emulator for AVD 'Android_Accelerated_x86'
Failed to open vm 4
Failed to create HAX VM
No accelerator found.
failed to initialize HAX: Invalid argument
Hax is enabled
Hax ram_size 0x40000000

Before, it was working perfectly, what do you think could the cause?

Thank in advance


How to open setting on iOS with Xamarin.forms for permission?

$
0
0

I am using the plugin for permission (Plugin.Permissions), but on iOS,once you deny on that permission dialog and it won't popup again(I am assume thats correct,cuz it never ask again,but on android it will keep popup the alert dialog even you choose deny). So my question is how can we go to setting page on iOS and turn it on manually on xamarin.forms?I have no clue how to do so, please advise! Thanks in advance!

Passing seed data to an app manually - SMS, other ideas?

$
0
0

Hello - We have an ecosystem that mandates us having our users enter URLs for specific servers. They may need to have 2, 3, 6 of them for various reasons. Any ideas of how we could pass them a formatted string of them in say an email or SMS message and if that block of text is in the clipboard say, our Xamarin.forms app could read it in? I'm not the developer on our project, but was a programmer in the past; currently doing UI/UX. I've seen this sort of thing done really well with license keys in a program called FTP Voyager way back when. The app simply looked in the paste buffer and imported -- after asking permission. Can mobile apps do the same?

Thanks!

Xamarin Form UWP solution build error (Type universe cannot resolve assembly or windows metadata)

$
0
0

Hello There,

We have been working on this Xamarin Forms project & everything worked like a charm until recently that the UWP solution wouldn't build. The error thrown here is also meaningless. Will appreciate your input.

How can i do to remove the title bar?

$
0
0

I have a App and when i run my App appear a blue bar on the top of my App. Is there how to remove that bar?

Is iOS Interface Designer/Storyboards broken?

$
0
0

I'm new to Xamarin and I'm finding the iOS interface designer to be unusable. Storyboards take several minutes to load - even blank ones - and often give the error that "There was a problem rendering this document", even if absolutely nothing was changed since it last loaded fine. My system is very ordinary: a Windows 10 PC running VS 2015, and a mid 2012 MacBook Pro. All software is up to date.

I've looked through various posts on this subject, and the slowness/unreliability of interface designer/storyboards always seems to be news to Xamarin, even though there are many reports of problems.

I've seen another thread suggest that the only way to go is to use XCode to design the storyboards, where others do the whole thing in code. That seems daunting but may be it's my only option?

So:
1. Is Interface Designer/Storyboards broken?
2. Are Xamarin doing anything about it?
3. What do you guys do as a viable alternative?

I'd also be interested to hear how many folks find Interface Designer/Storyboards to work perfectly well and fast. At the moment I've no idea what speed/reliability is the norm.

Where to get and How to add Windows Phone SDK for Visual Studio for Mac

$
0
0

Hi,

I wanted to ask where to get the Windows Phone SDK for Xamarin / Visual Studio for Mac and how to add it to Visual Studio?

Thanks,
Jassim

Submitting to the Play Store - Google Play App Signing - how to use it?

$
0
0

We're publishing an app to the Play Store for the first time, and have turned on Google Play App Signing.

I've downloaded the App Signing Key and Upload Key, but am struggling to work out what I do with them when doing my final release build.

The Archive tool (in Visual Studio For Mac) asks for a Keystore. Do I need to add the Upload Certificate to a Keystore and use this? The various documents and walk-throughs don't fully describe the process.

Any help would be appreciated!


Set Static IP Address programmatically on Xamarin Android

$
0
0

I'm trying to implement from this code as:

public void SetStaticIPConfiguration(WifiConfiguration wifiConfiguration,InetAddress ip,int prefix,InetAddress host,InetAddress dNS1,InetAddress dNS2) { //IPAssignment setEnumField(wifiConfiguration, "STATIC", "ipAssignment"); //IP Object linkProperties = getField(wifiConfiguration, "linkProperties"); Class laClass = Class.ForName("android.net.LinkAddress"); Constructor laConstructor = laClass.GetConstructor(new Class[] { InetAddress.Class, int.Class }); Object linkAddress = laConstructor.NewInstance(ip, prefix); ArrayList mLinkAddressList = (ArrayList)getDeclaredField(linkProperties, "mLinkAddresses"); mLinkAddressList.Clear(); mLinkAddressList.Add(linkAddress); //Gateway Class routeInfoClass = Class.ForName("android.net.RouteInfo"); Constructor routeInfoConstructor = routeInfoClass.GetConstructor(new Class[] { InetAddress.Class}); Object routeInfo = routeInfoConstructor.NewInstance(host); ArrayList mRouteList = (ArrayList)getDeclaredField(linkProperties, "mRoutes"); mRouteList.Clear(); mRouteList.Add(routeInfo); //DNS ArrayList mDNSList = (ArrayList)getDeclaredField(linkProperties, "mDnses"); mDNSList.Clear(); mDNSList.Add(dNS1); mDNSList.Add(dNS2); } public static Object getField(Object obj,string fieldName) { Field f = obj.Class.GetField(fieldName); Object o = f.Get(obj); return o; } public static Object getDeclaredField(Object obj, string fieldName) { Field f = obj.Class.GetField(fieldName); f.Accessible = true; Object o = f.Get(obj); return o; } public static void setEnumField(Object obj,string value,string fieldname) { Field f = obj.Class.GetField(fieldname); f.Set(obj, Enum.ValueOf(f.Type, value)); }

However, I can not find a corresponding code for this line:
Constructor laConstructor = laClass.GetConstructor(new Class[] { InetAddress.Class, int.Class });
Errors at InetAddress.Class and int.Class:

An object reference is required to access non-static field, method, or property 'Object.Class'
'int' does not contain a definition for 'Class'

I created a field: InetAddress inet; out of this method and change above to inet.Class. I don't know this is correct or not, but first error is gone.
Please tell me this is correct or not, and how about int.Class error? And please help me check the other lines too.

Label alignment reseting

$
0
0

Hello!

I have an wierd problem where the text alignment resets to leftside when the bound property is updated. I don't know why this would happen, all graphics in the view are made trought the xaml so nothing should affect the alignment.

Xaml:

Have anyone seen something similar before?

Problem with backwards compability

$
0
0

Hello!

I have written an Application using xaml forms and PCL. However I needed to do some custom renderers. These worked great until a friend of mine tested on older hardware. Now, the project is using the default settings and should have support to android 4.0.0 but 4.4.0 does not work.

The line giving problems is:
Control.ProgressTintList = Android.Content.Res.ColorStateList.ValueOf(Color.FromHex("#3fcf31").ToAndroid()); //Change the color

The crash says that the "ProgressTintList" does not exist. Any ideas why this happens? It should be supported, right? Workarounds are also appreciated!

Fragment GetActivity

$
0
0

Hi, I ran into problem with fragment .. I get through the xamarin guides, stackoverflow etc., but havent find any acceptable solution.

I need to show a Toast from inside the fragment, but as it seems to be, there is no GetActivity() in c#
Any solutions I have found, was for java :(

Toast.MakeText( /GET ACTIVITY IN WHICH IS FRAGMENT HERE/, "OK", ToastLength.Long).Show();

Any help please?

ItemSelected and the item Highlighted are not the same in listView.

$
0
0

Hi, All.
I am a beginner with Xamarin Form, and I have a problem about ListView when developing a mobile phone project communicated with WCF.
Here is it:
After I get a list from remote WCF, and show the list imformation with ListView with Xamarin Form, it work well.
But sometime when I tap the item and Navigating to a detailed page. it seems get wrong:
The item highlighted (means which I tapped) and the ItemSelected ( SelectedItemChangedEventArgs.SelectedItem with the eventhandle of ItemSelected) are not same, why does this happen? I had tried to find answer about this in StackOverFlow, but unfortunitily, I got no answer, did anyone have this problem before?
Thanks for any help!
Here is the code about it.
In XAML file:

In XAML file- behind code:

public async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
Patient patient = args.SelectedItem as Patient;
if (patient != null)
{
PatientInfo patientInfo = new PatientInfo(ref patient);
NavigationPage.SetHasNavigationBar(patientInfo, false);
await Navigation.PushAsync(patientInfo);
}
}

And I debugging with Android phone, and there is detailed info: when I debugging with PC connected to Android Phone, it seen work well, but if App run in the Android phone without debugging mode, it went wrong frequently as what I mentioned above.

Viewing all 204402 articles
Browse latest View live


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