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

Entry Custom Renderer Frame.Width is always 320

$
0
0

I'm writing a custom Entry class to have Entry controls on iOS only have an underline. In my custom renderer, the Frame.Width is always 320 no matter how wide I make the control. I draw the underline that size and the entry field is obviously longer because the typing goes beyond the end of the underline.

I'm doing the drawing in OnElementChanged. Should I be doing it somewhere else?

What am I doing wrong?


Period of Day Picker

$
0
0

Hi, could anyone point me in the right direction on how to create a period of day picker as depicted in the image? (Taken from Outlook app on Android)
At the moment I am using two TimePickers to select a start and end time, but would like something slicker.

Thanks!!

Xamarin Forms WebView and GestureRecognizers not working with android

$
0
0

Hello,

I have created a webview to load my local HTML file. My application requires to load another HTML file as the user swipes right or left. I have created this functionality with the following code:

    <WebView
        x:Name="HtmlView"
        Grid.Row="1" 
        Source="{Binding HTMLFile}" 
        HorizontalOptions="FillAndExpand" 
        VerticalOptions="FillAndExpand"
        GoBackRequested="Handle_GoBackRequested"
        GoForwardRequested="Handle_GoForwardRequested"
        >
        <WebView.GestureRecognizers>
        <SwipeGestureRecognizer Direction="Left" Swiped="Handle_SwipedLeft"/>
        <SwipeGestureRecognizer Direction="Right" Swiped="Handle_SwipedRight"/>
        </WebView.GestureRecognizers>
    </WebView>

And Implemented the handlers as shown below:

    void Handle_SwipedLeft(object sender, Xamarin.Forms.SwipedEventArgs e)
    {
        flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard2.html");
        HtmlView.Reload();
    }

    void Handle_SwipedRight(object sender, Xamarin.Forms.SwipedEventArgs e)
    {
        flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard3.html");
        HtmlView.Reload();
    }

This works completely fine with iOS, however if try running it on android (using the emulator) the handlers are not called at all. Is there something that I am missing here?

Thanks

Xamarin Forms: Load a contentpage when tap push notification android

$
0
0

I completed receiving test notification from FCM console. Now I am trying to open a page when tapping the notification. Any ideas about how to achieve this? I have searched the internet but can't find a working solution. I am also able to send the notification through the postman.

Trying to not update on page rotation

$
0
0

Hello!

Maybe this is a very basic question, but I can't find the right words combination in order to find an answer.
I have a page with its ViewModel. I'm using code behind to trigger a reloading command, from my VM, in the "OnAppearing" event, only if ViewModel.IsInitialized is true.
This way, when using navigation back and forth, I'm sure that the page's content is refreshed everytime I'm back to it.

But there's one problem: it triggers the reload command when I change from portrait to landscape or viceversa. How can I avoid that?
I wasn't able to find a list of Xamaring events... except for Xamaring events like meetings and speechs in real world ^^U

Also, it looks like it triggers too when I'm in a child or grand-child page. What I'm missing?

Custom Renderer for Span

$
0
0

Hello devs!

I'm trying to make a Custom Renderer to ignore the ****android**** accessibility configurations in the ****Span Class****, to ****not re-scale the font size****.
I have made successfully renderer for the Label class but not for Span class.. Can someone help me? :D

****My Label Custom Renderer is Above!****
<br /> using System;<br /> using System.ComponentModel;<br /> using Android.Widget;<br /> using FreePlay.Droid;<br /> using Xamarin.Forms;<br /> using Xamarin.Forms.Platform.Android;</p> <p>[assembly: ExportRenderer(typeof(Span), typeof(IgnoreAcessibilitySpan))]<br /> namespace FreePlay.Droid<br /> {</p> <pre><code>public class IgnoreAcessibilitySpan : LabelRenderer { protected void setFontSizeAgain() { var nativeControl = (TextView)Control; var xfControl = Element; //e.NewElement; if (nativeControl != null && xfControl != null) nativeControl.SetTextSize(Android.Util.ComplexUnitType.Dip, xfControl.Font.ToScaledPixel()); } protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e) { base.OnElementChanged(e); setFontSizeAgain(); } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); setFontSizeAgain(); } }

}

Xamarin forms - Can deploy to iPhone but not iPad (error code 0xe8008015)

$
0
0

I have a Xamarin Forms app that works well on Android and iPhone. But when I am trying to debug my Xamarin.Form application in iPad, it shows the following error. Can anybody please suggest?

error MT1006: Could not install the application
'/Users/iotg/Library/Caches/Xamarin/mtbs/builds/MyApp.iOS/976da0c08e8bb7065faabf8e70b7bd35/bin/iPhone/Debug/MyApp.iOS.app' on the device 'MyiPad': AMDeviceSecureInstallApplicationBundle returned: 0xe8008015.

Configuration
Visual Studio: Visual Studio Professional 2017 for Windows 10
Test Mode: Debug
Xcode:10.2.1
iOS: 12.2
iPad: iPad Pro 12.9

Thanks for your help.

Local reminder notifications

$
0
0

Hello I need help, I'm working on an application that has to control the day and time to deliver tasks. The logic of the application is as follows: the user must enter date and time to deliver his task, after this the application must show a local notification the day and time that the user entered, but still can not make that happen, could give me suggestions


FFImageLoading issue on iOS

$
0
0

Hi,

I am using FFImageLoading library in my Xamarin.forms project to display animated GIF splash screen. In android it is behaving as expected, but in iOS I am getting the below error. Please help if any of you have come across the same issue.

/Users/name/Documents/Code/: Error MT2101: Can't resolve the reference 'System.Void SkiaSharp.SKPath::AddRoundRect(SkiaSharp.SKRect,System.Single,System.Single,SkiaSharp.SKPathDirection)', referenced from the method 'SkiaSharp.SKPath FFImageLoading.Svg.Platform.SKSvg::ReadElement(System.Xml.Linq.XElement,System.Collections.Generic.Dictionary`2<System.String,System.String>)' in 'SkiaSharp, Version=1.68.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756'. (MT2101)

Thanks in advance,

standard C# samples for Xamarin.Forms

$
0
0

https://developer.xamarin.com/samples/xamarin-forms/all/

The Microsoft Xamarin official website only has samples for how to use the UI.
In fact, most standard C# foundation can be used to Xamarin.Forms, just like the Socket.
But there is no samples for them.

Maybe there has some samples for use standard C# foundation in Xamarin.Forms, just I am not found.
Is there any official website for it?

Terminate Xamarin Forms App | Quitting Xamarin Forms App

$
0
0

Is there any other better way to terminate Xamarin Forms App ? Than this ?

In Main Project PCL

MainPage.Xaml.cs(The Page Where i want to Terminate)

    protected override bool OnBackButtonPressed()
            {
                Device.BeginInvokeOnMainThread(async () =>
                {
                    var result = await this.DisplayAlert("Alert!", "want to exit?", "Yes", "No");
                    if (result)
                    {
                      var closer = DependencyService.Get<ICloseApplication>();
                      closer?.closeApplication();
                    }
                });
                return true;
            }

Interface

         public interface ICloseApplication
            {
                void closeApplication();
            }

Android

  [assembly: Xamarin.Forms.Dependency(typeof(CloseApplication))]
namespace XForms.Droid
{
    public class CloseApplication : ICloseApplication
    {
        public void closeApplication()
        {
            Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
        }
    }
}

IOS

 [assembly: Xamarin.Forms.Dependency(typeof(CloseApplication))]
namespace XForms.Droid
{
         public class CloseApplication : ICloseApplication
                {
                    public void closeApplication()
                    {
                        Thread.CurrentThread.Abort();
                    }
                }
        }

List View not listens to XAML but Sized as number of initial itemssource.

$
0
0

I have listview. It's Vertical and Horizontal Options are fill in Xaml.
I am setting it's source as somelist in OnAppearing Window.
protected override void OnAppearing() { base.OnAppearing(); ((ListView)FindByName("attributesList")).ItemsSource = d.attributes; }
Listview will size itself as number of items in attributes. If two list view will be size of two rows. If something added it scrolls but size is of only two rows. If initially there is no item. Nothing is shown. If I comment this Itemssource line, The list will expand on whole page as needed.

How to get data instantly from a api?

$
0
0

I am using newtonsoft to get json data like
HttpClient client = new HttpClient();
var response = await client.GetStringAsync("http:................");
var items = JsonConvert.DeserializeObject<List>(response);

But it take too much time to show in a list view as there are only 3000++ data.
It take much time for searching also . how can i improve the search and getting data quickly ?

How can I create and auto-start a service app, just after installation without launching it?

$
0
0

I want to create and auto-start a background service app just after it is installed from the play store, without launching it. The purpose to the service app is to initialise a centralised local database that needs to be accessed and modify by two other Xamarin apps. How can I achieve this?

Field changed to null???

$
0
0

I was building a demo for another question on here when i came across another lovely problem with the Name field of a Model object in my List changing to null when you press a button to fire a command.

The first time you press either button, it works fine. But when you go back and select the other button, it changes the Name field to null.

The code below will explain it more:

ViewModel:

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Windows.Input;
    using Xamarin.Forms;

    namespace BindingExample
    {
      public class MainViewModel : INotifyPropertyChanged
      {
        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged(string propertyName)
        {
          if (PropertyChanged != null)
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private ObservableCollection<Model> _listOfModels { get; set; }
        public ObservableCollection<Model> ListOfModels
        {
          get { return _listOfModels; }
          set
          {
            if (_listOfModels != value)
            {
              _listOfModels = value;
            }
          }
        }

        private Model _selectedModel;
        public Model SelectedModel
        {
          get { return _selectedModel; }
          set
          {
            _selectedModel = value;
            OnPropertyChanged("SelectedModel");
          }
        }

        private bool _isPickerSelected = false;
        public bool IsPickerSelected
        {
          get { return _isPickerSelected; }
          set
          {
            _isPickerSelected = value;
            OnPropertyChanged("IsPickerSelected");
          }
        }

        private bool _isListSelected = false;
        public bool IsListSelected
        {
          get { return _isListSelected; }
          set
          {
            _isListSelected = value;
            OnPropertyChanged("IsListSelected");
          }
        }

        public ICommand OnPickerSelectedCommand { get; }
        public ICommand OnListSelectedCommand { get; }

        public MainViewModel()
        {
          OnPickerSelectedCommand = new Command(OnPickerSelectedCommandExecuted);
          OnListSelectedCommand = new Command(OnListSelectedCommandExecuted);

          ListOfModels = new ObservableCollection<Model>();

          ListOfModels.Add(new Model
          {
            Name = "Picker",
            Numbers = new List<Number>(){
              new Number {Name = "One", Value = 1 },
              new Number {Name = "Two", Value = 2 },
              new Number {Name = "Three", Value = 3 },},
            Enabled = true
          });
          ListOfModels.Add(new Model
          {
            Name = "List",
            Numbers = new List<Number>(){
              new Number {Name = "One", Value = 1 },
              new Number {Name = "Two", Value = 2 },
              new Number {Name = "Three", Value = 3 },},
            Enabled = false
          });
        }

        private void OnPickerSelectedCommandExecuted()
        {
          SelectedModel = ListOfModels.Where(e => e.Name == "Picker").First();
          IsPickerSelected = true;
          IsListSelected = false;
        }

        private void OnListSelectedCommandExecuted()
        {
          SelectedModel = ListOfModels.Where(e => e.Name == "List").First();
          IsPickerSelected = false;
          IsListSelected = true;
        }
      }

      public class Model
      {
        public string Name { get; set; }
        public List<Number> Numbers { get; set; }
        public bool Enabled { get; set; }
      }

      public class Number
      {
        public string Name { get; set; }
        public int Value { get; set; }
      }
    }

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="BindingExample.MainPage">
      <StackLayout>
        <StackLayout Orientation="Horizontal">
          <Label Text="Models:"/>
          <Button Text="Picker" Command="{Binding OnPickerSelectedCommand}"/>
          <Button Text="List" Command="{Binding OnListSelectedCommand}"/>
        </StackLayout>
        <StackLayout IsVisible="{Binding IsPickerSelected}" Orientation="Vertical">
          <Label Text="Select a Value:" />
          <Picker
            Title="picker_select"
            ItemsSource="{Binding Numbers}" BindingContext="{Binding SelectedModel}"
            ItemDisplayBinding="{Binding Name}"
            SelectedItem="{Binding Name}"/>
        </StackLayout>
        <StackLayout IsVisible="{Binding IsListSelected}" Orientation="Vertical">
          <Label Text="Select Options:"/>
          <ListView ItemsSource="{Binding Numbers}" BindingContext="{Binding SelectedModel}"
                    HasUnevenRows="True"
                    SeparatorColor="Gray"
                    VerticalOptions="FillAndExpand"
                    HorizontalOptions="FillAndExpand">
            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                  <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
                    <Label Text="{Binding Name}" TextColor="Black" FontSize="Small" 
                                 HorizontalOptions="StartAndExpand"/>
                    <Switch HorizontalOptions="End"/>
                  </StackLayout>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>
        </StackLayout>
      </StackLayout>
    </ContentPage>

code behind:

    using Xamarin.Forms;

    namespace BindingExample
    {
      public partial class MainPage : ContentPage
      {
        public MainPage()
        {
          InitializeComponent();
          BindingContext = new MainViewModel();
        }
      }
    }



Picker - Binding Context

$
0
0

Currently have a picker that won't display the list of items that are bound to it.

I have a ListView that is using the exact same binding, and it displays the list no problems at all.

Code below:

        <StackLayout IsVisible="{Binding IsDropdownControl}">
          <Label Text="Task Field:"/>
          <Picker Title="Select a Value:"
                        ItemsSource="{Binding FieldItems}" BindingContext="{Binding SelectedField}"
                        ItemDisplayBinding="{Binding Name}"
                  SelectedItem="{Binding SelectedFieldItem}"
                  HorizontalOptions="FillAndExpand">
          </Picker>
        </StackLayout>


        <StackLayout IsVisible="{Binding IsCheckBoxControl}">
          <Label Text="Select Options:"/>
          <ListView ItemsSource="{Binding FieldItems}" BindingContext="{Binding SelectedField}"
                HasUnevenRows="True"
                SeparatorColor="Gray"
                VerticalOptions="FillAndExpand"
                HorizontalOptions="FillAndExpand">
            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                  <StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
                    <Label Text="{Binding Name}" TextColor="Black" FontSize="Small" 
                             HorizontalOptions="StartAndExpand"/>
                    <Switch HorizontalOptions="End" 
                              IsToggled="{Binding Value}"/>
                  </StackLayout>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>
        </StackLayout>

InitializeComponent does not exist in the current context error

$
0
0

Hi,

The error CS0103 (The name 'InitializeComponent' does not exist in the current context) has started appearing after doing a build of our Xamarin Forms solution. The build, however, appears to have succeeded in spite of this error message?

This started happening after adding the first XAML ContentPage to the PCL project. If I remove the XAML ContentPage then the error disappears.

I've tried installing the latest Alpha channel update on both my Windows (Visual Studio) machine and my Mac build host but it hasn't made any difference.

Please advise ASAP as we would like to use XAML for our ContentPages but may have to revert to using C# code to build the UI if the XAML approach is not viable.

Regards,
Andy

How can I customize the refreshing icon for a Pull to Refresh Listview?

$
0
0

I would like to modify the existing refreshing animation for the Pull to Refresh for a Listview.

I've created a Listview with the following properties:

RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
CachingStrategy="RecycleElement"

And the pull to refresh action works like I want it to, but the animation used is the standard Android and iOS animation. I would like to customize this by adding some text, changing the position of the loading icon and changing the color schemes.

I've achieved the perfect layout by placing a grid over my listview and binding the IsVisible to the same IsRefreshing, but it only shows after the refreshing command has started (which makes sense of course...) and I would like this grid to slide down when starting the pull down, showing while refreshing and dissappearing when the refreshing is done.

Any help is much appreciated!

I'm struggling to get databinding to work

$
0
0

So I am pulling from a table called "Person" in a SQLite database. This table has several properties including the PersonId and PersonName. There are many "people" in this table. I am trying to pull a specific PersonName and populate a Button's text with it. What is coming out is just a blank button with no text. Here is what I have in xaml:

<ContentPage.Content>
    <ListView x:Name="peopleList">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell Height="30">
                    <StackLayout Padding="5">
                        <Button Text="{Binding People[0].PersonName}" />
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>

Here is the code behind:

public List<Person> People { get; set; }

    protected override void OnAppearing()
{
    PopulatePeople();

}



    public async void PopulatePeople()
    {
        List<Person> People = await App.PeopleRepo.GetAllPeople();
            peopleList.ItemsSource = People; 
     }

Here is the GetAllPeople() method defined in the PeopleRepository class:

    public SQLiteAsyncConnection conn;
    public PeopleRepository(string db)
    {
        conn = new SQLiteAsyncConnection(db);
        conn.CreateTableAsync<Person>().Wait();
    }

        public async Task<List<Person>> GetAllPeople()
    {
        try
        {
             return await conn.Table<Person>().ToListAsync();
        }
        catch (Exception ex)
        {
            Status = string.Format("Failed to retrieve data. {0}", ex.Message);
        }

        return new List<Person>();
    }

I just can't get this working. I have struggled some with my understanding of databinding and have researched it a ton and I feel that this should work. What am I missing?

HotReload LiveReload LiveXaml [Mac] [Windows] [nuget package] [opensource]

Viewing all 91519 articles
Browse latest View live


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