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

Use BackBlaze with Xamarin

$
0
0

Hi, did anyone use BackBlaze cloud service with Xamarin? Because I need some help, can't install the B2 NuGet packages due to problems with the .NET version tha Xamarin use and when i try to make a header calling from HttpWebRequest it lead me to errors.
If someone use this api before I would be glad if I could ask you a few questions :smile:


How chage an Image using Mode TwoWay?

$
0
0

Hi All,

I'm try change an image dynamically using the Mode TwoWay,

Page -

ViewModel -

public string ImageBattery
    {
        get { return _imageBattery; }
        set
        {
            _imageBattery = value;
            OnPropertyChanged("ImageBattery");
        }
    }

Method -

public void loadInf(DetailtsModel detailts){

    ...

    var battery = detailts.battery;

    if(battery >= 80)
    {
        ImageBattery = "Battery100.png";
    }
    else if(battery >= 50)
    {
        ImageBattery = "Battery50.png";
    }
    else
    {
        ImageBattery = "Battery20.png";
    }
}

ListView Swipe Gestures

$
0
0

Hello!

I was wondering whether there are native controls of ListView for swipe gestures (i.e. for deleting), and if not, maybe someone from Xamarin could answer if there is any plan for such a implementation in the near future?

If not, anyone know a good place to get me started on making such a thing for Android and iOS using custom renderers? I figure it is a common enough feature that possibly there is some boilerplate code to do such a thing.

Thank you!

Print in xamarin.forms

$
0
0

Hello everyone.

I am developing a cross-platform application on xamarin.forms, in this I must generate a receipt and print it on a printer wifi.
Can I perform this action in a cross-platform project?

how to highlight the button color when it click ?

$
0
0

Hi,
I have 5 buttons on my screen. by default button text color is blue color and I didn't set the border and background color for those controls.
Here I want to highlight the clicked button. How can we do this in Xamarin forms using Xaml and view models ?
is it possible to do this without using the codebehind file(.cs file).

Any help appreciated. Thank you.

SkiaSharp - Graphics basics

$
0
0

I am fairly new to Xamarin, Cross-platform, Forms, Graphics, etc. I see the SkiaSharp form samples. I looked at the DrawXamagon code. I modified it, to draw a polygon. Only a small part of it is shown, because my polygon is too large, (Upside down also, I think), off center, etc., etc. The sample code has predefined hard coded sizes of the sample image, display area, etc., that do not fit my polygon image.

Is there a sample anywhere that does not have hard coded values, and that is commented as it goes along. I do not care what it draws (triangle, circle, polygon, whatever). Something that besides creating the image to be displayed, that also determines the size of the display area, and, the image to be displayed, and then scales the image so that it fits, and, is centered? Is this there already in one of the samples...if so where?

Update view on Xamarin Form after getting scanned barcode from Fragment

$
0
0

I have created fragment to run and get data for scanned barcode . I am passing that data in Portable project to show on Content Page. I am able to pass the data to it but can not update view.
Any idea how I can update view of my Content page in Xamarin Form (in Portable Code)after getting data from fragment in Android App.

How to change the style of bindable selectedItem in a custom StackLayout ViewCell

$
0
0

Hi All,

With the following example:

<custom:StackLayout ItemsSource="{Binding Items}" ItemSelectedCommand="{Binding SelectCommand}">
    <custom:StackLayout.ItemTemplate>
        <DataTemplate>
            <ViewCell>
        <StackLayout Style="{DynamicResource StackLayoutItem_Dark}">
                   <Label Text="Test" Style="{DynamicResource Label_Dark}" />
        </StackLayout>
            </ViewCell>
        </DataTemplate>
    </custom:StackLayout.ItemTemplate>
</custom:StackLayout>

When the SelectedItem event raised we can bind it with ViewModel command, but how can I change the inner viewcell stacklayout & label styles at the same time?

-K


Exception: Only the original thread that created a view hierarchy can touch its views

$
0
0

The code below works on Windows Phone but when running on Android I am getting the following exception : android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

        public ButtonLoggerPage()
                {
                    // Create the Button and attach Clicked handler.
                    Button button = new Button
                    {
                        Text = "Log the Click Time"
                    };

                    button.Clicked += OnButtonClicked;
                    opusClient.LoginCheckCompleted += OpenReadLogincheck;

                    this.Padding = new Thickness(5, Device.OnPlatform(20, 0, 0), 5, 0);

                    tbSyncItemLbl = new Label { };

                    // Assemble the page.
                    this.Content = new StackLayout
                    {
                        Children = { button,new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand,

                        BackgroundColor = Color.Gray,
                        Content = loggerLayout}
                        }
                    };
                }

        void OnButtonClicked(object sender, EventArgs args)
            {

                        loginCheck();

            }

     public void loginCheck()
            {
                try
                {


                    client.LoginCheckAsync(username, password);
                }
                catch (Exception e)
                {

                    receiveErrors = 22;
                }
            }

    void OpenReadLogincheck(Object sender, LoginCheckCompletedEventArgs e)
    {


                if (e.Result != null)
                {
                    LoginStatus = e.Result.Value;
                    if (e.Result == 1)
                    {
                        addMessage("Login Succeeded", Direction.Download);

                    }

}
}

        public enum Direction { Upload, Download, DownloadFailed, UploadFailed };

             public void setSyncItem(string itemName, Direction dir)
                    {
                        tbSyncItemLbl.Text += itemName +" " + Environment.NewLine;


                        if (dir == Direction.Download)
                        {
                            this.tbSyncItemLbl.TextColor = Color.FromHex("B5DF26");
                        }
                        else if (dir == Direction.Upload)
                        {
                            this.tbSyncItemLbl.TextColor = Color.FromHex("527EA5");
                        }
                        else if (dir == Direction.DownloadFailed)
                        {
                           this.tbSyncItemLbl.TextColor = Color.FromHex("FF0000");
                        }
                        else if (dir == Direction.UploadFailed)
                        {
                           this.tbSyncItemLbl.TextColor = Color.FromHex("FF0000");
                        }

                        this.tbSyncItemLbl.YAlign = TextAlignment.Center;

                    }

         private void addMessage(string item, Direction dir)
                {
                          setSyncItem(item, dir);
                        loggerLayout.Children.Add(tbSyncItemLbl);
                }

        Label tbSyncItemLbl ;

How to handle Push notifications?

$
0
0

For android versions 5.0 and above , the app should be either in foreground or background to receive push notifications; so if the user swipe off the app from the recent screen or task manager the push notifications don't work, how to over come this issue?

XAML control 'does not exist in the current context'

$
0
0

I'm getting an intermittent error where my XAML codebehind complains that a control 'does not exist in the current context'.

This is my .xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp_Mobile.IncidentReport"
             Title="Report Incidents">
  <StackLayout Spacing="5" x:Name="layoutIncident">
    <Label Text="Incident Type:" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
    <Picker x:Name="IncidentTypePicker1" Title="Incident Type" HorizontalOptions="FillAndExpand">
      <Picker.Items>
        <x:String>Theft</x:String>
        <x:String>Fire</x:String>
        <x:String>Accident</x:String>
      </Picker.Items>
    </Picker>
    <Label Text="Incident Description:" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
    <Editor x:Name="IncidentDescription" WidthRequest="400" HeightRequest="200" />
    <Button Text="Submit" Clicked="OnButtonClicked" />
    <Label x:Name="lblMessage" Text="" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
  </StackLayout>
</ContentPage>

And this is my .xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace MyApp_Mobile
{
    public partial class IncidentReport : ContentPage
    {
        int count = 0;

        public IncidentReport()
        {
            InitializeComponent();
        }

        public void OnButtonClicked(object sender, EventArgs args)
        {
            lblMessage.Text = IncidentTypePicker1.SelectedIndex.ToString() + " " + IncidentDescription.Text;

            count++;
            ((Button)sender).Text =
                String.Format("{0} click{1}!", count, count == 1 ? "" : "s");
        }
    }
}

The IDE (Visual Studio 2013) sometimes complains that IncidentTypePicker1 and IncidentDescription do not exist, and sometimes it does not complain and I am able to Build and Deploy the app. Is there any reason for this intermittent error?

Xamarin.Forms 2.3.3.180

$
0
0

Important notes

  • Xamarin.Forms 2.3.3 depends on a Xamarin installation of Cycle 8. Users upgrading from Xamarin.Forms 2.3.2 (or earlier) will experience numerous compile errors if they attempt to build without first upgrading their Xamarin installation.

  • When upgrading Xamarin.Forms take care not to simply "update all" as that will update the Xamarin.Android.Support packages to an incompatible version. More info here.

  • In 2.3.3 we are deprecating Classic support (More info here).

Breaking changes

  • [UWP] TabbedPage ContentPresenter is now of type FormsPresenter instead of TabbedPagePresenter. This is an internal change only that will only affect users explicitly targeting TabbedPagePresenter in the UWP project.

2.3.3.180

Nuget package here.

Release Notes

Add authenticode signing.
No other changes.

2.3.3 sr1

Nuget package here.

Bug Fixes

  • 47707 - "47707 – Page.Toolbar is covering page.content with XF.UWP on Windows 10 phone" (PR)

  • 47295 - "[UWP] Toolbar is Clipped When Using a NavigationPage" (PR)

  • 47950 - "2.3.3 Regression: XAML compilation fails with behavior property and StaticResource" (PR)
  • 47971 - "XF UWP ListView Items no longer display" (PR)
  • 48105 - "Xamarin.Forms.Theme ResourceDictionary MergedWith fails in current build" (PR)
  • 48158 - "Hidden controls become transparent, static property does not bind" (PR)
  • 48242 - "Binding to constants not working any more in Xamarin Forms 2.3.3" (PR)
  • 48554 - "Bound static property does not call setter in custom view" (PR)
  • 48726 - "[UWP] Toolbar Covering Page Content" (PR)
  • [XamlC] assigned derived type to generic BP (PR)
  • [Xaml] support non-int enums (PR)

2.3.3 stable

Nuget package here.

Bug Fixes

  • 46195 - "Navigation Stack Errors in Xamarin.Forms.2.3.3.163-pre3" (PR)

2.3.3-pre4

Nuget package here.

Bug Fixes

  • 44338 - "Displaying context action causes ArgumentNullException when another item's context actions are already displayed on iOS10." (PR)

  • "[Win] Toolbar placement works with initial value" (PR)

  • "[Android] SoftInputMode works with initial value" (PR)

2.3.3-pre3

Nuget package here.

Bug Fixes

  • 44129 - "[Forms Android] Removing and adding items to TabbedPage BindingContext crashes the app when VM uses MvvmLight property Set()-method" (PR)

  • 44166 - "41166 - Fix MasterDetailPage/NavigationPage leaks on iPad" (PR)

  • 44596 - "Grey/Blank Screen when switching MainPage to MasterDetail with TabbedPage" (PR)
  • 45010 - "[2.3.3] 45010 – Forms Sample "WorkingWithListview" throw exception with WinPhone8.1" (PR)
  • 44166 - "MasterDetailPage instances do not get disposed upon GC; instance accumulation crashes app with OOM error using Forms 2.3.2.118-pre1 and AppCompat" (PR)
  • Don't unsubscribe/resubscribe the listener to the same INPC (PR)
  • 44886 - "UWP Listview ItemSelected event triggered twice for each selection" (PR)
  • [iOS] Fixes KVO native binding (PR)
  • Make CreateNativeControl virtual instead of abstract (PR)
  • 43993 - "iOS: ListView size does not return to normal after keyboard disappears" (PR)

  • 39768 - "PanGestureRecognizer sometimes won't fire completed event when dragging very slowly" (PR)

  • 42602 - "Custom BoxView Renderer Does Not Render All Its Children Elements" (PR)
  • [Xaml] Xaml native views and bindings for WP8.1 (PR)
  • [XamlC] Compiled converters (PR)
  • [Xaml] allow compatible arguments for x:Factory (PR)
  • [XAMLC] specify type and default value for native bindings (PR)
  • [2.3.3-pre2] [XamlC] supports enum and consts in x:Static (PR)
  • Reuse Handler when invoking on main thread (PR)

2.3.3-pre2

Nuget package here.

New Features

Support native view declaration in Xaml, and native Bindings

The following Xaml is valid, and works as expected:

<?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:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
             xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
             xmlns:formsandroid="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.Platform.Android;targetPlatform=Android"
             xmlns:win="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime;targetPlatform=Windows"
       x:Class="Xamarin.Forms.Controls.XamlNativeViews">
    <ContentPage.Content>
        <ios:UILabel Text="{Binding NativeText}" View.HorizontalOptions="Start"/>
        <androidWidget:TextView Text="{Binding NativeText}" x:Arguments="{x:Static formsandroid:Forms.Context}" />
        <win:TextBlock Text="Foo"/>
    </ContentPage.Content>
</ContentPage>
  • native views are automagically wrapped into the appropriate wrapper
  • xmlns defined on a non-matching targetPlatform (see TargetPlatform enumeration) are ignored
  • you can bind to property of native views. A proxy is created on the fly for supporting 2-Way bindings if possible. If the native property doesn't implements INPC, or support Observable (on iOS), or is a DependencyProperty (on UWP), you can pass an UpdateSourceEventName parameter to the binding expression.
  • if you set, or bind to, attached BindableProperty to a native view that will be wrapped in a X.F.View, those property values and binding are transferred to the wrapper. See HorizontalOptions in the sample above.

Platform Specifics

Introducing Platform Specifics! Features or behaviors that apply to one platform only can now be implemented without requiring custom renderers. These new features/behaviors can then be accessed easily via a fluent code API or XAML.

Vendors can easily add their own Platform Specifics by attaching Effects to them (see 63a924d and 1f9482e for complete example).

This feature implements the framework that enables the new API and also includes several examples of platform specific features, which can be previewed using the Platform Specifics gallery page:

  • Blur support for any VisualElement on iOS

  • Translucent navigation bar on iOS

  • Partially collapsed navigation bar (with icons!) on MasterDetailPage on Windows
  • Toolbar placement options on Windows
  • AdjustResize/AdjustPan on Android (known issue: AdjustResize disables status bar color)

Bug Fixes

  • 32733 - "32733 – Switching Activity crash in 1.4.4.6392" (PR)

  • 35132 - "35132 – Pages are not collected when using a Navigationpage"

  • 39768 - "PanGestureRecognizer sometimes won't fire completed event when dragging very slowly" (PR)
  • 39908 - "Back button hit quickly results in jumbled pages" (PR)
  • 41463 - "CarouselView Crashes with "Sequence Does not Contain a Matching Element""
  • 42061 - "App crashes when registering an app link entry with invalid thumbnail url" (PR)
  • 42112 - "42112 - CarouselView throws error on Android while moving"
  • 42341 - "Page not removed from NavigationStack when hit Back quickly on iOS" (PR)
  • 42519 - "Text Truncation in UWP"
  • 42697 - "Slow swipe - System.InvalidOperationException: Sequence contains more than one element [CarouselView]"
  • 43230 - "DisplayAlert returns unexpected value when Escape key hit on UWP" (PR)
  • 43328 - "DisplayActionSheet() double-tap NullReferenceException crash Win8.1" (PR)
  • 43354 - "Button IsEnabled binding is position dependent" (PR)
  • 43450 - "Faulty syntax of Grid.RowDefinition wasn't caught with XamlC"
  • 43516 - "[UWP] Changing FontAttribute on a label to NONE changes font size as well" (PR)
  • 43530 - "[Android] Resuming app throws IllegalStateException from fragment manager"
  • 43726 - "Setting TabbedPage.ItemsSource to Null Causes Crash" (PR)
  • 43774 - "Appearing does not trigger for the first time for Tabpages in Android" (PR)
  • 43892 - "Xamarin.Forms.TabbedPage with FormsAppCompatActivity OnAppearing Troubles"
  • 44056 - "Picker Focused/Unfocused events not fired on iOS 10 preview" (PR)

Other fixes

  • iOS10 fixes

2.3.3-pre1

Only internal. There were no public artifacts/nuget packages for pre1.

Image As Background

$
0
0

Hello,

I am working with Xamarin Forms and would like to use an image as the background for some pages. I have several Views and Layouts on different pages, and would like to overlay them onto a background image, selecting the image based on the page. I found how to use a solid color for the background, by setting the BackgroundColor on various components (like the primary StackLayout I have on a given page), but is it possible to use an image instead of a solid color? If so, could you include an example (short, quick, and dirty is perfectly fine). If not, does an alternative solution exist, perhaps using Renderers? I am targeting Android and iOS currently, if that helps at all.

Thank you.

Getting error Activity has been destroyed

Profiling my app, memory leak in CocoaTypesetter

$
0
0

I'm not 100% sure how to read this, however in profiling my app, I'm seeing huge memory allocations regarding setting a font, however we're not using any custom fonts in the app.

Can anyone make heads or tails of this?


How to refresh page from view model after navigating to it via PopAsync

$
0
0

We are currently testing Xamarin.Forms as an app development platform in our company. While trying to port our desktop app to Xamarin.Forms we encountered an issue. It seems that X.F is not updating pages according to view model changes when we navigate to them with the PopAsync method.

What we are actually doing is: We navigate to a page with a ListView via PushAsync, navigate further to a page for filtering the ListView via PushAsync and after entering the filter criteria navigate back to the page with the ListView via PopAsync but the ListView isn't updating properly although the List bound to the ItemsSource of the ListView in the view model has been updated as expected.
Maybe FYI, the view model of the page with the ListView is updated before we navigate back to it. Don't know if this is worth mentioning.
If we do the same except for navigating to the page with the ListView the second time with PushAsync it works as expected, but this is obviously not what we want to do.

Binding a Data Trigger

$
0
0

Hi guys,
I have a XAML page with a label which Text property is binding with a ViewModel property named SALDO.
I want to see the label's TextColor Red when the value from SALDO is <0.
I have tried this, there is no compilation error, but the TextColor never change.

    <Label
      Style="{StaticResource TextoGeneral}"
      Text="{Binding Saldo, StringFormat='{0:C0}'}">
      <Label.Triggers>
        <DataTrigger TargetType="Label"
                     Binding="{Binding Saldo}"
                     Value="<0">
          <Setter Property="TextColor" Value="Red" />
        </DataTrigger>
      </Label.Triggers>
    </Label>

Any idea?
Tanks

Data binding and passing object to custom control.

$
0
0

Let say I created a custom control to replace

<ContentView BackgroundColor="{Binding Blah.Type}">
    <Label Text="{Binding Blah.Name}" TextColor="{Binding Blah.Color}" />
</ContentView>

by

<local:CustomLabel Text="{Binding Person.Name}" Type="{StaticResource inverse}" />

So my custom label xaml would look like:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" x:Class="Blah.CustomLabel"
    BackgroundColor="{Binding Type}">
    <Label x:Name="Label2" Text="{Binding Text}" TextColor="{Binding TextColor}" />
</ContentView>

and my custom label class would look like:

public partial class CustomLabel : ContentView {

        public CustomLabel()
        {
            InitializeComponent();
            BindingContext = this;
        }

        public static readonly BindableProperty TextProperty =
            BindableProperty.Create("Text", typeof(string),
                typeof(CustomLabel), string.Empty);

        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set{ SetValue(TextProperty, value); }
        }

        public static readonly BindableProperty TextColorProperty =
            BindableProperty.Create("TextColor", typeof(Color), typeof(CustomLabel), Color.FromHex("#fff"));

        public Color TextColor
        {
            get { return (Color)GetValue(TextColorProperty); }
            set{ SetValue(TextColorProperty, value); }
        }

        public static readonly BindableProperty TypeProperty =
           BindableProperty.Create("Type", typeof(Color), typeof(CustomLabel), Color.FromHex("#999"));

        public Color Type
        {
            get { return (Color)GetValue(TypeProperty); }
            set { SetValue(TypeProperty, value); }
        }
    }

I set BindingContext = this to force the ContentView BindingContext to be this view so the binding work.
I can add this custom control to my view by

<local:CustomLabel Text="Something!" TextColor="Red" />

This work just fine, my problem is when passing or attach a bindable object to the custom control. Ex:

<local:CustomLabel Text="{Binding Person.Name}" TextColor="Red" />

The TextProperty always null.

Added Context Actions to ViewCell hangs the listView

$
0
0

Hello:
I have this Cell template:

public BaseDisclosureWithActionTemplateCell() : base()
{
InitializeComponent();

        var moreAction = new MenuItem { Text = "More" };
        moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("{Binding ActionCommand}"));
        moreAction.Clicked += (sender, e) =>
        {
        };
        var deleteAction = new MenuItem { Text = "Delete", IsDestructive = true }; // red background
        deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("{Binding ActionCommand}"));
        deleteAction.Clicked += (sender, e) =>
        {
        };
        //ContextActions.Add(moreAction);
        //ContextActions.Add(deleteAction);
    }

When I add the more and DeleteAction to ContextActions, Listview never gets loaded.
The indicator spins and spins, view cells are not created apparenttly.

My ListView is defined like this:>

I can't get the cells to show up.

The baseTemplate selector is defined like this:
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
var b = item as BaseModel;
switch (b.ViewType)
{
case ViewType.Action:
return ActionTemplate;
case ViewType.DefaultAction:
return DefaultActionColorTemplate;
case ViewType.Disclosure:
return DisclosureTemplate;
case ViewType.DisclosureWithAction:
return DisclosureWithActionTemplate;
case ViewType.Download:
return DownloadActionTemplate;
}
return DisclosureTemplate;
}

I would love some feedback on this. This is a very strange behavior of kind I have not seen before
Anyone has any idea what is going?

A

ScrollView doesn't apears without layout.ForceLayout()

$
0
0

Hello , i have some strange stuff with scrollview.

How it works, on start scrollview is empty and its content loads from server, when i get results i set scrollview content.
On Android everything is fine , but on ios scrollview will apear only if i call layout.ForceLayout or if i go to another page and then go back to this page.

Viewing all 91519 articles
Browse latest View live


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