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

Focused or OnFocuseChange events not fires

$
0
0

I have custom entries, and i want to know when it focused but it is never happening. I tried to catch it in custom android class, and in xaml event Focused but it did nothing.
I had this problem before too, but wasnt solving it.
Here is a class. Events in comment blocks.

`using Android.Support.Design.Widget;
using Android.Text;
using Android.Views;
using Android.Views.InputMethods;
using GitRemote.CustomClasses;
using GitRemote.Droid.DependencyServices;
using GitRemote.Droid.Renderers;
using GitRemote.ViewModels;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Color = Xamarin.Forms.Color;
using TextChangedEventArgs = Android.Text.TextChangedEventArgs;
using View = Android.Views.View;

[assembly: ExportRenderer(typeof(MaterialEntry), typeof(MaterialEntryRendererDroid))]

namespace GitRemote.Droid.Renderers
{
public class MaterialEntryRendererDroid : Xamarin.Forms.Platform.Android.AppCompat.ViewRenderer<Entry, View>
{
private TextInputLayout _nativeView;

    private TextInputLayout NativeView => _nativeView ?? ( _nativeView = InitializeNativeView() );

    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);



        if ( e.OldElement != null ) return;

        // MaterialEntry Render Staff
        #region
        var ctrl = CreateNativeControl();
        SetNativeControl(ctrl);

        SetText();
        SetHintText();
        SetBackgroundColor();
        SetTextColor();
        SetIsPassword();
        #endregion

        if ( Control != null )
            switch ( e.NewElement.ClassId )
            {
                case "LoginEntry":
                    ViewSaver.SaveLoginView(Control);
                    //Element.Focused += (sender, args) =>
                    //{
                    //    ViewSaver.LastView = "LoginEntry";
                    //};
                    break;

                case "PasswordEntry":
                    SetSendButtonAction();
                    ViewSaver.SavePasswordView(Control);

                    //Element.Focused += (sender, args) =>
                    //{
                    //    ViewSaver.LastView = "PasswordEntry";
                    //};
                    break;

            }
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if ( e.PropertyName == Entry.PlaceholderProperty.PropertyName )
        {
            SetHintText();
        }

        if ( e.PropertyName == Entry.TextColorProperty.PropertyName )
        {
            SetTextColor();
        }

        if ( e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName )
        {
            SetBackgroundColor();
        }

        if ( e.PropertyName == Entry.IsPasswordProperty.PropertyName )
        {
            SetIsPassword();
        }

        if ( e.PropertyName == Entry.TextProperty.PropertyName )
        {
            SetText();
        }

    }

    private void EditTextOnTextChanged(object sender, TextChangedEventArgs textChangedEventArgs)
    {
        Element.Text = textChangedEventArgs.Text.ToString();
        NativeView.EditText.SetSelection(Element.Text.Length);
    }

    private void SetText()
    {
        NativeView.EditText.Text = Element.Text;
    }

    private void SetIsPassword()
    {
        NativeView.EditText.InputType = Element.IsPassword
            ? InputTypes.TextVariationPassword | InputTypes.ClassText
            : InputTypes.TextVariationVisiblePassword;
    }

    public void SetBackgroundColor()
    {
        NativeView.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
    }

    private void SetHintText()
    {
        NativeView.Hint = Element.Placeholder;
    }

    private void SetTextColor()
    {
        if ( Element.TextColor == Color.Default )
            NativeView.EditText.SetTextColor(NativeView.EditText.TextColors);
        else
            NativeView.EditText.SetTextColor(Element.TextColor.ToAndroid());
    }

    private TextInputLayout InitializeNativeView()
    {
        var view = FindViewById<TextInputLayout>(Resource.Id.textInputLayout);
        view.EditText.TextChanged += EditTextOnTextChanged;
        return view;
    }

    protected override View CreateNativeControl()
    {
        return LayoutInflater.From(Context).Inflate(Resource.Layout.TextInputLayout, null);
    }

    /// <summary>
    /// If Action of our entry is Send than call method from Portable
    /// </summary>
    private void SetSendButtonAction()
    {
        NativeView.EditText.EditorAction += (sender, e) =>
        {
            if ( e.ActionId == ImeAction.Send )
            {
                ( ( LoginingPageViewModel )Element.BindingContext ).OnLogInTapped();
            }
            else
                e.Handled = false;
        };
    }


}

}`


How can I get ScrollView to work on Windows Phone 8.1?

$
0
0

Hey guys, I am currently stuck on a what it seems to be a basic issue. In my first page I have a ScrollView containing a Grid. Both Android and iOS behave as expected. However, the least expected one ( Windows Phone) behaves abnormally, as in the ScrollView will not scroll in any direction. I have tried to click on a Label to get it to work but nothing, it's frozen ....

How can I get the content to scroll in this ScrollView guys ?

Thank you all !!!!

Xamarin.Forms.TextCell doesn't Display Details

$
0
0

Hey guys, I've been hunting around for a couple days for anyone that has had this problem haven't found anything. Below I have a basic ListView with TextCell DataTemplate, The Text Property populates as you would expect, the Detail is Nowhere to be found not even a space where it would be. I have tested just throwing a TextCell without binding into a TableView in this project and get the same result. Either I am missing something really basic or it is downright bizare. I have tried flipping the Binding properties and both of them populate in the TextProperty and neither in the DetailProperty. The govTrac ContentPage is pushed to a Navigation page in the calling fuction. I attached a picture of what the listview looks like.

image
ObservableCollection<CommunicationBase.BindingClass> returnSet = CommunicationBase.ComsClasses.getBindingDataObservable("stuff to get data");
var myTemplate = new DataTemplate(typeof(TextCell));
myTemplate.Bindings.Add(TextCell.TextProperty, new Binding("x.myValue"));
myTemplate.Bindings.Add(TextCell.DetailProperty, new Binding("x.x.x.myValue"));
ContentPage govTrac = new ContentPage();
ListView lv = new ListView();
lv.ItemsSource = returnSet;
lv.ItemTemplate = myTemplate;
return govTrac;

image

Why did upgrading from v2.0.1.6505 to v2.1.0.6521 break this awesome reusable ActivityIndicator?

$
0
0

Here's the original class (please be aware that I call the ActivityIndicator a "spinner" instead):

using Xamarin.Forms;

namespace Tester
{
    [ContentProperty("Content")]
    public sealed class LayoutWithSpinner : ContentView
    {
        private readonly ContentView _contentView;
        private readonly RelativeLayout _spinnerLayout;
        private readonly ActivityIndicator _spinner;

        public bool IsSpinning
        {
            get
            {
                return (bool)GetValue(IsSpinningProperty);
            }
            set
            {
                SetValue(IsSpinningProperty, value);
            }
        }

        public static readonly BindableProperty IsSpinningProperty =
            BindableProperty.Create<LayoutWithSpinner, bool>(
                spinner => spinner.IsSpinning,
                false,
                propertyChanged: (bindable, value, newValue) =>
                {
                    var ctrl = (LayoutWithSpinner)bindable;
                    ctrl._spinnerLayout.IsVisible = newValue;
                    ctrl._spinner.IsRunning = newValue;
                });

        public new View Content
        {
            get { return _contentView.Content; }
            set { _contentView.Content = value; }
        }

        public LayoutWithSpinner()
        {
            _spinner = new ActivityIndicator { Opacity = 1, IsRunning = false };
            _spinnerLayout = new RelativeLayout { BackgroundColor = Color.Silver, Opacity = 0.4, IsVisible = false };
            _spinnerLayout.Children.Add(_spinner,
                xConstraint: Constraint.RelativeToParent(p => 0.4 * p.Width),
                yConstraint: Constraint.RelativeToParent(p => 0.4 * p.Height),
                widthConstraint: Constraint.RelativeToParent(p => 0.2 * p.Width),
                heightConstraint: Constraint.RelativeToParent(p => 0.2 * p.Height));

            _contentView = new ContentView();

            var absoluteLayout = new AbsoluteLayout
            {
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions = LayoutOptions.Fill
            };

            absoluteLayout.Children.Add(_contentView, new Rectangle(0f, 0f, 1f, 1f), AbsoluteLayoutFlags.All);
            absoluteLayout.Children.Add(_spinnerLayout, new Rectangle(0f, 0f, 1f, 1f), AbsoluteLayoutFlags.All);

            base.Content = absoluteLayout;
        }
    }
}

Which would be used like this:

<?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:Tester"
             x:Class="Tester.MainPage">
  <local:LayoutWithSpinner IsSpinning="{Binding CommandThatRunsAsync.SomeBooleanProperty}">
    <StackLayout>
      <Label Text="Here is some stuff."/>
      <Button Command="{Binding CommandThatRunsAsync}"/>
    </StackLayout>
  </local:LayoutWithSpinner>
</ContentPage>

The result was that the spinner would happily pop over and spin on whatever was inserted as the content. After the upgrade of Forms the spinner never appears, but the injected content is still visible and works fine. I've also tried hardcoding the IsSpinning property to True just to be sure, but I still never see it. Debugging seems to show me that after upgrade, the setter for the Content property is never hit (and it is hit before the upgrade).

I know there were three changes in nearby areas at that time:
1) ContentView had TemplatedView inserted as its new parent class
2) ContentView used to just have a Content property of type View but that got wrapped as a Bindable property
3) The generic typed BindableProperty.Create was obsolesced

Immediately after the upgrade I am given a green squiggle on the IsSpinningProperty because of #3 above, so I replaced my Bindable property creation with the following, which actually debugs as expected as the bound bool is changed:

public static readonly BindableProperty IsSpinningProperty = BindableProperty.Create(nameof(IsSpinning),typeof(bool),typeof(LayoutWithSpinner),false,propertyChanged:OnIsSpinningPropertyChanged);

private static void OnIsSpinningPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
    var ctrl = (LayoutWithSpinner)bindable;
    ctrl._spinnerLayout.IsVisible = (bool)newvalue;
    ctrl._spinner.IsRunning = (bool)newvalue;
}

But I never see my spinner ever pop up now. Any ideas?

Best theming options for iOS?

$
0
0

I've developed a recent Xamarin Forms project using the Android emulator due to ease of use, occasionally checking the iOS app on the simulator to verify that it functioned correctly. Now that I'm basically done, the Android application looks great, but the iOS app looks absolutely horrible. I'm not doing anything crazy with layouts, just using StackLayouts, AbsolutelyLayouts, and Grids to create a card-like view in some areas, and standard ListViews in other areas.

The MasterDetailPage menu looks really bad in iOS. And most of the other areas in the app just look unpolished in general, despite it looking like a commercial app in Android.

Are there any options to style the iOS app so that it looks acceptable? Anything similar to FormsAppCompatActivity for Android, which seems to automatically make the app look good? I'm aware of UINavigationBar.Appearance and the like, but I haven't done too much research on what's possible there.

I realize that Xamarin Forms uses the native look and feel of the platform, but the iOS app needs some serious polish before I would even consider releasing it. If anyone is available to help via Skype today or tomorrow, I will happily pay for your time as this is really important.

Getting "Access Denied" on Some iOS Devices Opening Socket

$
0
0

I am getting "Access Denied" when trying to open a socket on some iOS devices. Here are some facts:

  1. Same code works on Android
  2. Happens on XF and native Xamarin iOS
  3. Only seems to happen on T-Mobile devices.
  4. The error occurs on both cell and wifi
  5. This is not an "Access Denied" from the target site, its coming from the OS
  6. I am using "Sockets For PCL" from Nuget. The developer has never seen the error.

I have attached a screen shot of the stack trace from a user (I do not have a T-Mobile device).

Is there a permission that needs to exist in the plist file for network access or something? I just cant figure out why its only on T-Mobile devices. Any thoughts would be much appreciated. Thank you.

Error inflating class android.support.v7.widget.Toolbar after updaring to v7.AppCompat Version 23.3

$
0
0

I am creating a Xamarin Forms Project and using android.support.v7.widget.Toolbar with FormsAppCompatActivity. The code I'm posting below was working with Xamarin.Android.Support.v7.AppCompat Version: 23.0.1.3

But after I upgraded to 23.3.0 this has started throwing Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.v7.widget.toolbar exception.

Here is my code for MainActivity

[Activity(Label = "AppMob.Client", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

        protected override void OnCreate(Bundle bundle)
        {
            FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
            FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            Xamarin.FormsMaps.Init(this,bundle);                        
            GoogleAnalyticsHelper.GetGASInstance().Initialize_NativeGAS(Application.Context);  //For GA initialization
            LoadApplication(new App());
        }
}

This is my code for Resource.Layout.toolbar

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />

Ad services with xamarin forms

$
0
0

What would be some good ad services that I could use for a new app I'm working on. I'm trying my first ad supported app. I was thinking of using video ads but I'm open to other good options.


Azure app service authentication problem on iOS

creating breadcrumb navigation in Xamarin Forms

$
0
0

Is there any component/plugin that helps creating breadcrumb navigation in Xamarin Forms?
for example: on GridView, when the user press on item go to another grid.. etc, and the breadcrumb navigation created based on the history of those clicks.

How do I remove the wide margins around images in a grid?

$
0
0

I am trying to make a grid of images but I am getting huge margins around each row for some reason. Here is what it looks like when I set Aspect to AspectFit: http://imgur.com/V7eM5nh, and the second image is when I set it to AspectFill. Any ideas? Here is my code but I can't get the forum thing to work right.
`Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
//new RowDefinition { Height = GridLength.Auto }

                new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
            },
            ColumnDefinitions =
            {
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
            }
        };

        grid.Children.Add(new Image
        {
            Aspect = Aspect.AspectFill,
            Source = ImageSource.FromFile("fortyfive_degrees.jpg"),
            // HorizontalOptions = LayoutOptions.Center
        }, 0, 0);

        grid.Children.Add(new Image
        {
            Aspect = Aspect.AspectFill,
            Source = ImageSource.FromFile("fortyfive_degrees.jpg"),
            // HorizontalOptions = LayoutOptions.Center
        }, 1, 0);

        grid.Children.Add(new Image
        {
            Aspect = Aspect.AspectFill,
            Source = ImageSource.FromFile("fortyfive_degrees.jpg"),
            // HorizontalOptions = LayoutOptions.Center
        }, 0, 1);

        grid.Children.Add(new Image
        {
            Aspect = Aspect.AspectFill,
            Source = ImageSource.FromFile("fortyfive_degrees.jpg"),
            // HorizontalOptions = LayoutOptions.Center
        }, 1, 1);

        grid.Children.Add(new Image
        {
            Aspect = Aspect.AspectFill,
            Source = ImageSource.FromFile("fortyfive_degrees.jpg"),
            // HorizontalOptions = LayoutOptions.Center
        }, 0, 2);

        grid.Children.Add(new Image
        {
            Aspect = Aspect.AspectFill,
            Source = ImageSource.FromFile("fortyfive_degrees.jpg"),
            // HorizontalOptions = LayoutOptions.Center
        }, 1, 2);

        // Accomodate iPhone status bar.
        // this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

        // Build the page.
        this.Content = new ScrollView
        {
            Content = grid
        };`

How to call Webview.Eval() after Rendered?

$
0
0

Hi, all. I have reached a problem when using HybridWebView.

In my portable part, I have a defined a class HybridWebView : WebView and a class HybridWebViewPageCS : ContentPage. In the HybridWebViewPageCS, I claim a variable hybridWebView, which is a HybridWebView object, in the Content. I also defined some evnts that will call hybridWebView.Eval() in the HybridWebViewPageCS.

However, after I render the HybridWebView in the IOS app, it seems that the hybridWebView.Eval() in the HybridWebViewPageCS is not working.

My question is, is there anyway to define a javascript evaluation function in the HybridWebViewPageCS that will work after render?

How can I use a Google Spreadsheet as a datasource in a Forms Portable project?

$
0
0

I am developing a cross platform app (iOS / Android) and would like to use a Google docs spreadsheet as the data source.

InkCanvas in Xamarin.Forms?

$
0
0

Hello guys,

I would like to write a App with Ink Supprt.
Is there a anyway to use Xamarin with pen support for Windows, iOS and Android? Maybe with a Forms-Object like InkCanvas for UWP Apps?

Thank you in advance for your help

Christian

Any Solution for PDF reader

$
0
0

hi
I am unable to find a solution for for PDF reader in Xamarin forms.
The solution provided on xamarin website

https://developer.xamarin.com/recipes/cross-platform/xamarin-forms/controls/display-pdf/

not working for me. It says

_**The webpage at file:///android_asset/pdfjs/web/viewer.html?file=file:///android_asset/Content/abc.pdf might be temporarily down or it may have moved permanently to a new web address. **_

Someone please suggest me some easy solution or plugin for this problem. If there is any plugin working for cross platform solution free/paid please suggest.


XAML Elemnents not available for UWP in Code

$
0
0

Hello,
I created a shared Project with a Droid an UWP Project and added a Page with a Button (x:Name="myButton") and a Label (x:Name="myLabel") in XAML.
Now after click the Button, Visual Studio gives the Hint: myLabel is available for Droid but not for UWP.

How can I work with XAML and XAML - Objects in Code with UWP?

Thanks

Forms app on iOS - AppDelegate does not have access to window selector

$
0
0

When you make an Xamarin forms app, the iOS target app's AppDelegate inherits from a base class as follows:

public class AppDelegate : Xamarin.Forms.Platform.iOS.FormsApplicationDelegate

The problem I am having is that we have some native code in a library that does the following:

UIWindow *mainWindow = [[UIApplication sharedApplication].delegate window];

In Xamarin this results in an error message:

Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[AppDelegate window]: unrecognized selector sent to instance 0x124dcd030

Is there a reason that the base class doesn't have access to the 'window' selector, and could this be remedied, either in my own AppDelegate subclass or in the Xamarin.Forms.Platform.iOS.FormsApplicationDelegate base class?

Merge two or N images in Xamarin.Forms

$
0
0

Is there any way (library, plugin, etc.) to merge images in Xamarin.Forms?

Thanks.

Xamarin Forms / PCL & Managed Extensibility Framework (MEF)

$
0
0

Hello,

I am developing a Cross Platform (Windows and Xamarin.Forms) Tool to Conquer Code Complexity and Visually Debug Single & Multi-Threaded Applications and Apps in ways I haven’t seen done before. I expect the tool to be released some-time in 2017. Through this tool you will be able to Visually see, in my Windows Tool, what is going on in your Single- or Multi-Threaded Xamarin App on your iPhone or Android device. Data is transferred over WiFi to the Windows Tool.

The system consists of a Windows Application (Vca) and a Library VcaRun that is linked with the Xamarin Forms code on your phone.

I would like to make functionality of VcaRun extensible thorugh MEF. I have searched the internet for info on compatibility Xamarin Forms / PCL compatibility of MEF methods, but have not been able to find relevant info.

This link indicates that it works on Phones (Windows Phones only ?)

System.Compostion.*_ is a lightweight version of MEF, which has been optimized for static composition scenarios and provides faster compositions. It is also the only version of MEF that is as a portable class library and can be used on phone, store, desktop and web applications. This version of MEF is available via NuGet and is documentation is available here

Can somebody please shed some light on this?

Fix orientation for one page in the app : is it possible with Xamarin.Forms?

$
0
0

Hello,

I make an app with one page who need to have a fix orientation (landscape, exactly). I try to fix the orientation for the specific page in Xamarin.Forms (XAML or C#), but it seems to be specific to each platform. I don't know if Xamarin.Forms have a cross-platform option to do it but my searches aren't conclusive.

Can anyone help me?

Thanks in advance.

Viewing all 91519 articles
Browse latest View live


Latest Images

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