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

Picker data not getting refreshed while changing it

$
0
0

Hi all,

I have two picker control in which on changing the list value in first dropdown the second picker values should change.But my values are not changed.

< xLabsControl:ExtendedPicker HorizontalOptions="FillAndExpand" IsVisible="False" x:Name="ProjectPicker"
ItemsSource="{Binding LineItemDetails.ProjectList}" DisplayProperty="Value" SelectedItem="{Binding SelectedProject,Mode=TwoWay}" > //This is my first picker.On changing any element from this the second picker value should change

< xLabsControl:ExtendedPicker HorizontalOptions="FillAndExpand" x:Name="TaskListPicker" IsVisible="False"
SelectedItem="{Binding LineItemDetails.SelectedTask,Mode=TwoWay}"> //This is the second picker

Codebehind
private async void SetTaskList(object sender, EventArgs e)
{
var s = sender as ExtendedPicker;
var item = s.SelectedItem as NameValue ;
if(item.Id!=0 && item.Id!= 9176)
{
var model = new AddLineItemPageModel();
await model.SetTaskNumber(item.Id);
if (Application.Current.Properties.ContainsKey("TaskList"))
{
// TaskListPicker.IsVisible = true;
var x = TaskListPicker.ItemsSource;
TaskListPicker.ItemsSource = null;

                TaskListPicker.ItemsSource = Application.Current.Properties["TaskList"] as ObservableCollection<NameValue>;

                 TaskListPicker.DisplayProperty = "Value";
               TaskButton.Text = "";
             //   TaskListPicker.IsVisible = false;
            }
        }
    }

NB:-After this on clicking task picker old values are populated


How to approach push notifications on Xamarin.Forms project?

$
0
0

So we are working on a pcl project and have our UI set in a page inside the PCL. There is a scenario where our client wants some information to be sent as a push notification. We already have our UI in place and our backend too. We are using Azure to store data and have successfully configured WAMS. However we are scratching head on how to make push notifications work on Android without creating a separate page layout / controls that are android specific.

tl;dr - how do we use the PCL page UI elements to trigger push notifications on an Android device?

Problems with the RelativeLayout class and adding children to it

$
0
0

Hello,

i have the following situation:

RelativeLayout test = new RelativeLayout ();

StackLayout companyStackLayout = new StackLayout {
    AnchorX = 0,
    Padding = new Thickness(-20,20,0,0),
    HeightRequest = 87,
    WidthRequest = 120,
    Children = {
        new Image () {
        Source = "CompanyActivateIcon",
        HeightRequest = 50,
        ClassId = "companyImage",

    },

    new Label {
    HorizontalTextAlignment = TextAlignment.Center,
    Text = "TestCompany",
    FontSize = 10,

    }
    }
};

test.Children.Add (companyStackLayout);

The add-method call ends in:

Error CS0121: The call is ambiguous between the following methods or properties: `Xamarin.Forms.RelativeLayout.IRelativeList<Xamarin.Forms.View>.Add(Xamarin.Forms.View, System.Linq.Expressions.Expression<System.Func<double>>, System.Linq.Expressions.Expression<System.Func<double>>, System.Linq.Expressions.Expression<System.Func<double>>, System.Linq.Expressions.Expression<System.Func<double>>)' and `Xamarin.Forms.RelativeLayout.IRelativeList<Xamarin.Forms.View>.Add(Xamarin.Forms.View, Xamarin.Forms.Constraint, Xamarin.Forms.Constraint, Xamarin.Forms.Constraint, Xamarin.Forms.Constraint)' (CS0121)

I'm not able to add children into a relative Layout atm. I have posted this bug already into the bugboard from Xamarin. I found a person who is heading into the same problem. Answer from the Xamarin support around 3 weeks ago was:

Jason Smith 2016-04-13 19:37:46 UTC
Thank you for your report. At this time there are no plans to implement any changes around this issue.

Warm regards,
Xamarin Forms Team

And now ?
I'm not able to add the children like in a stacked layout because this

RelativeLayout layout = RelativeLayout {
    Childen = {
        .....
        }
}

is not working.This is not working because there is an missing interface from the xamarin sdk side.
Is anyone out there who is having an idea what i can do here? I can't rewrite the layout with more then 20 views.

Thx and kindly regards
Norman (C64Gamer)

Dynamically measure StackLayout height

$
0
0

Hi,

I would like to create an StackLayout and measure its Height at runtime (to account for accessiblity font size, variable width etc). In order to do this I'm adding it to the ContentPage (as IsVisible=false).

The problem I'm having right now is that I'm getting different height values at different times - I assume it is because I'm not awaiting the ChildAdded event of the parent layout.

Do you have a sample of how to correctly do this? Or is there a better way to get the height?

Thanks!

Chris

TableView with long action-menu and items?

$
0
0

Hello!
I need create fullwidth-in-table-swipe menu like this? With images?
Have Xamarin.Forms any standart components for it? Or other solution?

Update: ListView show only menu without images, and only two items. If i have more items - it show first and button with text "More". I need very different behavior :-)

SQLite and ListView

$
0
0

Hello, i have a strange question. Maybe somebody know what is it.

I have ListView with simple data (without using SQLite database there, even without any sqlite on this Page, no task, no anything), but if i clicked 5+ times on Listview cell, app crashes with unhandled exception. (Only on Android, ios and winphone works great).

Do anyone know why this can happened?
p.s. Sorry my bad english and some logs.

05-06 18:11:08.467 D/dalvikvm( 2753): GC_CONCURRENT freed 370K, 9% free 22674K/24756K, paused 0ms+0ms, total 4ms
05-06 18:11:09.143 D/dalvikvm( 2753): GC_EXPLICIT freed 122K, 9% free 22560K/24756K, paused 0ms+1ms, total 7ms
05-06 18:11:09.143 D/Mono    ( 2753): GC_OLD_BRIDGE num-objects 312 num_hash_entries 335 sccs size 331 init 0.00ms df1 0.08ms sort 0.02ms dfs2 0.05ms setup-cb 0.03ms free-data 0.03ms links 28/28/22/1 dfs passes 675/359
05-06 18:11:09.143 D/Mono    ( 2753): GC_MINOR: (Nursery full) pause 3.74ms, total 3.77ms, bridge 0.00ms promoted 1680K major 1680K los 870K
05-06 18:11:09.143 D/Mono    ( 2753): DllImport searching in: '/system/lib/libsqlite.so' ('/system/lib/libsqlite.so').
05-06 18:11:09.143 D/Mono    ( 2753): Searching for 'sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2' due to 'undefined symbol: sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2' due to 'undefined symbol: sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2A' due to 'undefined symbol: sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2A' due to 'undefined symbol: sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): DllImport searching in: '/system/lib/libsqlite.so' ('/system/lib/libsqlite.so').
05-06 18:11:09.143 D/Mono    ( 2753): Searching for 'sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2' due to 'undefined symbol: sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2'.
In mgmain JNI_OnLoad
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2' due to 'undefined symbol: sqlite3_close_v2'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2A' due to 'undefined symbol: sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): Probing 'sqlite3_close_v2A'.
05-06 18:11:09.143 D/Mono    ( 2753): Could not find 'sqlite3_close_v2A' due to 'undefined symbol: sqlite3_close_v2A'.
05-06 18:11:09.151 E/mono    ( 2753): 
05-06 18:11:09.151 E/mono    ( 2753): Unhandled Exception:
05-06 18:11:09.151 E/mono    ( 2753): System.EntryPointNotFoundException: sqlite3_close_v2
05-06 18:11:09.151 E/mono    ( 2753):   at (wrapper managed-to-native) SQLitePCL.SQLite3Provider+NativeMethods:sqlite3_close_v2 (intptr)
05-06 18:11:09.151 E/mono    ( 2753):   at SQLitePCL.SQLite3Provider.SQLitePCL.ISQLite3Provider.sqlite3_close_v2 (IntPtr db) [0x00000] in <filename unknown>:0 
05-06 18:11:09.151 E/mono    ( 2753):   at SQLitePCL.raw.sqlite3_close_v2 (SQLitePCL.sqlite3 db) [0x0000b] in <filename unknown>:0 
05-06 18:11:09.151 E/mono    ( 2753):   at SQLite.SQLite3.Close2 (SQLitePCL.sqlite3 db) [0x00000] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:3296 
05-06 18:11:09.151 E/mono    ( 2753):   at SQLite.SQLiteConnection.Dispose (Boolean disposing) [0x0009a] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:1601 
05-06 18:11:09.151 E/mono    ( 2753):   at SQLite.SQLiteConnection.Finalize () [0x00000] in /Users/fak/Dropbox/Projects/sqlite-net/src/SQLite.cs:1569 

Xamarin.Forms VS Xamarin.IOS/Android/Windows10

$
0
0

Hi there

We are quite new with this platform. We've noticed that there are 2 approaches of building up mobile app one is Xamarin.Form and the other one is Xamarin.IOS/.Andorid/UWP

We are trying to building 2 app below and what sort of type of approach that we should to take.

Sport activity app with main functionality are:

  1. Login/Logout using Facebook/Twitter account or custom one
  2. Local/server database sync just in case there is internet connection
  3. List of activity
  4. Detail activity
  5. Add/Edit/Delete activity
  6. Report

Slideshow app with main functionality are:

  1. Login/Logout
  2. Local/server database sync just in case there is internet connection
  3. List of slides (slide could be an image or pull out from external API)
  4. Detail slide
  5. Add/Edit/Delete slide
  6. Slideshow

Not able to open Windows Phone app in device

$
0
0

i have created a cross platform project and the app was successfully deployed and working fine in both Android and iOS device. But for windowsPhone after the installation of .appx file, when i tried to open the app in device, my app's getting opened and closed at the instance itself. But in windows phone emulator it working fine.

Also no error message or indication like ("Your App has crashed"). any idea or suggestion why i am getting like this?


Is it possible to debug DepencyService calls

$
0
0

I've been experimenting with back4app and quickly put up an app that talks to the back4app server. I implemented the API calls for each platform using dependency injection as described in the DependencyService guide. That was easy to do and everything worked like a Swiss watch. BUT, (yea there is a but), when I tried to put a break point at a statement with a DendencyService.Get() the debugger exploded and the app crashed.
The break point always gets hit but as soon as I click on 'continue', the app crashes.

any idea why that happens? could it be because dependency service does stuff under the hood which the debugger cannot figure out at run time. I don't know. I am just speculating.

cheers,

How to Control Xamarin Forms ListView SelectedItem ViewCell Visibility?

$
0
0

In Xamarin Forms XAML, I want to hide part of ViewCell if it is not selected. For example the second label with text="Show only if selected". How to do that?

<ListView x:Name="listView">
     <ListView.ItemTemplate>
         <DataTemplate>
             <ViewCell>
                 <StackLayout>
                     <Label Text="Always Show it"/>
                     <Label Text="Show only if selected" IsVisible={Binding somewhere?}/>
                 </StackLayout>
             </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

What other options are there to create ContextActions with icons for iOS?

$
0
0

Just looking for a visual way to represent options for list items that will allow an image or icon and not just text (for iOS). It doesn't need to be a contextAction, just using that as an example.

Thanks,

Unable to target android 6.0 and api level 23

$
0
0

Guys,

Need some urgent help here. I have installed api 23 sdk from sdk manager but yet i unable to see any android 6.0 options or api level 23 option in both target framework and target android version settings.

Any advices for this ?

Properly Scaling Images in Stack Layout

$
0
0

So I'm kinda new to coding with Xamarin.Forms and I'm not certain what I'm doing wrong with my XAMl code.

My objective is to get 4 images to auto-scale to fit it's StackLayout container. I've tried using every Aspect variable and the HorizontalOptions/VerticalOptions as well. I don't know if it's because the images are so large or maybe I'm just missing something.

<AbsoluteLayout >
  <Image Source="ButtonBackground.png" Aspect="AspectFit"
                              HorizontalOptions="FillAndExpand"
                              VerticalOptions="Center"/>

  <StackLayout Orientation="Horizontal" HorizontalOptions="Center" >
    <Image x:Name="BtnFB" Source="Button2_FB.png" Style="{StaticResource ImageButton}"/>
    <Image x:Name="BtnTW" Source="Button2_Twitter.png" Style="{StaticResource ImageButton}"/>
    <Image x:Name="BtnWS" Source="Button2_Website.png" Style="{StaticResource ImageButton}"/>
    <Image x:Name="BtnEM" Source="Button2_Email.png" Style="{StaticResource ImageButton}"/>
  </StackLayout>
</AbsoluteLayout>

This is the style I'm using for the Images at this moment. It's not really important, but I figured I would post it just in case.

<Style x:Key="ImageButton" TargetType="Image">
  <Setter Property="Aspect" Value="AspectFit"/>
</Style>

If anyone has an idea why the images scale outside the bounds of their StackLayout bounds I'd really appreciate the help. Honestly any help at all would be a blessing.

Set a minimum height for labels in a grid that can expand, if needed, to accommodate large strings

$
0
0

I'd like to be able to accommodate potentially large strings (especially due to localization) by having my grid row height grow past a set minimum. Setting the RowDefinition to GridUnitType.Auto will expand, but it will also squish smaller labels unless I have a height request for the labels. But setting a height request for the labels doesn't allow for expansion of the row - hence some of the text may not be visible.

Does anyone know of a solution?

The first attachment is a screenshot with HeightRequest set for the labels so that my rows are at least a certain height, but the row height will not expand, leaving the long string not entirely visible.

The second attachment is a screenshot with HeightRequest removed for the labels, which expands the row height with the large string, but squishes the row height for the smaller string, which I don't want.

Here is my code.

public class GridSamplePage : ContentPage
{
    protected static Style MyLabelStyle = new Style(typeof(Label)) {
        Setters = {
            new Setter { Property = Label.HeightRequestProperty, Value = 48 },
            new Setter { Property = Label.VerticalOptionsProperty, Value = LayoutOptions.FillAndExpand },
            new Setter { Property = Label.FontSizeProperty, Value = 16 },
            new Setter { Property = Label.VerticalTextAlignmentProperty, Value = TextAlignment.Center },
            new Setter { Property = Label.TextColorProperty, Value = Color.Black }
        }
    };

    protected readonly Label ShortLabel1 = new Label { 
        Style = MyLabelStyle,
        HorizontalTextAlignment = TextAlignment.End,
        Text = "1st short string",
    };
    protected readonly Label LongLabel = new Label { 
        Style = MyLabelStyle,
        HorizontalTextAlignment = TextAlignment.End,
        Text = "Really, really, very, mucho long string that will wrap a bunch",
    };
    protected readonly Label ShortLabel2 = new Label { 
        Style = MyLabelStyle,
        HorizontalTextAlignment = TextAlignment.Start,
        Text = "2nd short string",
    };
    protected readonly Label ShortLabel3 = new Label { 
        Style = MyLabelStyle,
        HorizontalTextAlignment = TextAlignment.Start,
        Text = "3rd short string",
    };

    public class ListSeparator : BoxView
    {
        public ListSeparator()
        {
            BackgroundColor = Color.Gray; 
            HeightRequest = 1;
            HorizontalOptions = LayoutOptions.FillAndExpand;
        }
    }

    public GridSamplePage()
    {
        var grid = new Grid {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            BackgroundColor = Color.White,
            ColumnSpacing = 12,
            RowSpacing = 0,
            ColumnDefinitions = {
                new ColumnDefinition { Width = new GridLength(0, GridUnitType.Absolute) }, // Left side margin
                new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }, // Left label
                new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) }, // Right label
                new ColumnDefinition { Width = new GridLength(0, GridUnitType.Absolute) }, // Right side margin
            },
            RowDefinitions = {
                new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }, // Line
                new RowDefinition { Height = new GridLength(48, GridUnitType.Auto) }, // First content row
                new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }, // Line
                new RowDefinition { Height = new GridLength(48, GridUnitType.Auto) }, // Second content row
                new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }, // Line
            }
        };

        grid.Children.Add(new ListSeparator(), left: 0, right: 4, top: 0, bottom: 1);
        grid.Children.Add(ShortLabel1,         left: 1, top: 1);
        grid.Children.Add(ShortLabel2,         left: 2, top: 1);
        grid.Children.Add(new ListSeparator(), left: 0, right: 4, top: 2, bottom: 3);
        grid.Children.Add(LongLabel,           left: 1, top: 3);
        grid.Children.Add(ShortLabel3,         left: 2, top: 3);
        grid.Children.Add(new ListSeparator(), left: 0, right: 4, top: 4, bottom: 5);

        Content = grid;
    }
}

Thanks!

codesign wants to sign using key "your dev key" in the keychain

$
0
0

I am trying to build an iOS app for Ad Hoc distribution. When I build, I get a popup on my Mac.

"codesign wants to sign using key "your dev key" in the keychain

do you want to allow access to this item?"

Clicking allow (Repeatedly) has no effect. Clicking deny cancels the build on my windows machine.

I recreated certificates, rebooted both machines..Don't know what try next.


How to stop audio

$
0
0

Hello everyone , i recently created a xamarin forms pcl project that play audio tracks from a button click. The problem i am facing is that when i start playing if i click the button again it does not stop the audio , how do i stop the track playing?
Bellow is the part of the code for starting
class AudioService2 : IAudio2
{

    public AudioService2() { }
    private MediaPlayer player2;
  public bool PlayMP3File(string fileName)
    {
        player2 = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw.intoyami);
        player2.Start();
        return true;
    }
}

Xamarin.Forms Android - Could not load assembly 'GooglePlayServicesLib, Version=1.0.0.0, Culture=

$
0
0

I'm having a bad Android day. In trying to fix an issue, I've created another problem. This seems to be the norm rather than the exception when making changes in Xamarin, which is why I don't like doing it. Anyway, below is the error message. This happens when I try to Build my Android project. This happened after I clicked update on the GooglePlayServices package under Packages. Prior to clicking update, I had a bunch of GooglePlay packages that all required updates. After updating the main one, I got a successfully updated message and then all the packages disappeared. This is when the problem started. Since then I have installed and removed GooglePlay using the SDK manager, but the problem still exists. To make matters worse, I can't find any lines that I could potentially comment out. Here is the full error code.

Target _ResolveAssemblies:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'GooglePlayServicesLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'GooglePlayServicesLib.dll'
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00000] in :0
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in :0
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (ICollection`1 assemblies, Mono.Cecil.AssemblyDefinition assembly, Boolean topLevel) [0x00000] in :0
at Xamarin.Android.Tasks.ResolveAssemblies.Execute () [0x00000] in :0
Task "ResolveAssemblies" execution -- FAILED
Done building target "_ResolveAssemblies" in project "/Users/bteague28/Development/FaceOffers-9/Xamarin_FaceOffers/FaceOffers/FaceOffers.Droid/FaceOffers.Droid.csproj".-- FAILED

Does anyone know how to fix this problem? Perhaps I need to update Mono?

Any help is much appreciated. Thanks!

Unable to compile projects after updating the nuget package for Xamarin Forms in Visual Studio 2015

$
0
0

Hello,

I am facing a complicated situation when trying to update the nuget package for Xamarin Forms. The scenario to recreate this bug is.

  1. Create a new Blank App (Xamarin Forms Portable). Wait until the folders and project is created.
  2. Add a new Forms XAML page to the Portable project.
  3. Write code or add controls and build the project. It works as expected and sometimes throws the error Initialize Component not found. The work around is to add a new XAML page and then rebuild it or close the project and re-open the project.

  4. Now click on Tools | Nuget Package Manager | Manage Nuget Package Manager for this solution.

  5. It will show that there are updates for the Xamarin Forms and Xamarin Android Support.
  6. Update everything in this package manager and then reopen the solution as asked.

Now from this point onward everything goes haywire and the solution will not compile but throw a string of errors as seen in the attachment.

As a consequence I am forced to use the default version of Xamarin Forms when creating new projects with Visual Studio 2015.

Is there any solution to use the updated version of Xamarin Forms so that we can ensure that the latest version is used as well as new features can be implemented in the project.


And another case is when updating the version of Xamarin Forms and using the latest version of SQL.NET PCL by Frank Kruger the insert or update or delete or querying from a database all fails.

But using this specific versions of the libraries as per the attached file

SQLite.Net.Async-PCL version 3.1.1
SQLite.Net.Platform.Xamarin.Android version 2.5.1
SQLite.Net-PCL version 3.1.1

Xamarin.Android.Support.v4 version 23.3.0
Xamarin.Forms version 2.2.0.31

I am able to develop an application that involves SQLite, inserting data, retrieving data, updating data.

I would like to know when will we get a new version of Xamarin Forms for Visual Studio so that the above mentioned bugs do not affect the development.

Thanks,

Rajesh.

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

Formatted Label with Xamarin.Forms

$
0
0

Can someone please show me how to use Xamarin.Forms.Label.FormattedText correctly?

I'm using Xamarin.Forms to write a Carousel based app, when I try

Label IntroductionTextLabel = new Label();
IntroductionTextLabel.FormattedText = "Test";

I get this error:

"'Xamarin.Forms.Label' does not contain a definition for 'FormattedText' and no extension method 'FormattedText' accepting a first argument of type 'Xamarin.Forms.Label' could be found (are you missing a using directive or an assembly reference?)"

Perhaps it's the version of Xamarin I'm currently using...

The next step would be using this to display some HTML.

Thanks for any help.

Viewing all 91519 articles
Browse latest View live


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