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

Crop image from file (after picking it up with MediaPlugin from James Montemagno)

$
0
0

Hello!
I use MediaPlugin from James Montemagno to get an image (github.com/jamesmontemagno/MediaPlugin). This saves an image file in a specified path, wether the user chooses to take the image from the camera or from the gallery.

Now, the only thing I have is the path of the image's file. I want to take this image and crop it automatically in a square (centered in the image) removing top and bottom excess (or left and right excess if the image is in landscape).

I have only found answers saying that I should use System.Drawing.Bitmap but this is an only Windows class... Any suggestion?


to drop ListView when clicking

$
0
0

whenever I click on the listview to call another page, it gets selected, making it impossible to click on that item again, how to solve it?

private async void MenuItemsListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var select = (MasterDetailPage1MenuItem)e.SelectedItem;

        if (select.Id == 0)
        {
            await App.NavigateMasterDetail(new Page1());
        }
        else
        {
            await App.NavigateMasterDetail(new Page2());
        }

        >>>>MenuItemsListView.SelectedItem = null; >>> Error
    }

The "ResolveLibraryProjectImports" task failed unexpectedly.

$
0
0

Can anyone please help me on this ? Getting always this error while rebuild the app in xamarin.forms. The "ResolveLibraryProjectImports" task failed unexpectedly.

Thanks in advance.

Has CarouselView been dropped?

$
0
0

I've been using CarouselView for a while now but the version has been a pre-release since July 2016.
Is this still being maintained or abandoned?

With the new XF app being created with .Net standard 2.0 instead of PCL the plugin is giving some compatibility issues, plus there are some missing key features and i am wondering if it is a dead end...

I was also reading this thread:
https://github.com/xamarin/Xamarin.Forms/pull/853

but i am not sure if we are supposed to find a different CarouselView as part of Xamarin Forms out of the box or not. It doesn't seem like so to me though.

Xamarin.forms Frame OutlineColor doesn't work on Android

$
0
0

Hey,

I am trying to have a frame which has a border around it and by setting the OutlineColor is does show up on iOS+WP but it doesn't on Android. I have been googling alittle and the issue gets changed to resolved even though it still persists.

Does anyone know a quick fix, since I need this border to complete my project.

Sincerely,

Luuk

Microsoft.Identity.Client.MsalException : authentication_ui_failed

$
0
0

I want to use Azure AD B2C with Microsoft.Identity.Client. But when I call this AuthenticationResult ar = await App.PCA.AcquireTokenAsync(App.Scopes, App.UiParent); . I get error authentication_ui_failed .
Any ideas? I have been stuck here for 3 days now..

How to integrate any payment gateway in Xamarin Forms App?

$
0
0

I just want to implement any payment gateway in my Xamarin.Forms app. Could you please suggest any plugin or any documentation from where I get some help.
My background language is c#.

Xamarin.Forms 3.0 release date

$
0
0

Is there any more recent information that can be shared as to the release date of Xamarin.Forms 3.0?

We are looking to start building a number of Xamarin apps and want to use the Embedding Feature as described in (https://blog.xamarin.com/glimpse-future-xamarin-forms-3-0/.

We would prefer to be able to start off with Native projects and embed Xamarin.Forms content especially to get early iterations of screens done which may later become fully native.

The roadmap states that this will be Q4 2017.

Many thanks,
Richard


Hi Developers. I'm creating an Application in Xamarin Forms, I need a Serious Help.

$
0
0

The application is about home repairing Service. It has two Sides one the client who will call the repairing person and other is a repairing peson who will come to repair.
I'm Stuck in A Problem, I won't Understand that what should I use to Send request through Client to Nearby Repairing Persons on their Apps, One who will Accept the Request will be connected to the Client. both will also get each others data. And they keep on Connected Until the Work is done

"Collection was modified; enumeration operation may not execute" error removing TableSections

$
0
0

I found a thread on removing TableSections from a TableView that was generated via XAML, which referred to this SO answer.

I tried doing the exact same thing but I end up with the following error:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

What am I missing?

FormattedText limitations only for iPhone 8 plus?

$
0
0

I have a Label with a lot of formatted text that is added to the Label with .FormattedText . I have tested this on a real iPhone 5, iPhone 8 emulator and the iPhone 8 Plus emulator. No problem while running on the iPhone 5 and 8, but running on the iPhone 8 Plus it doesn't display any text at all. If I remove some of the text it works fine!
Is there some known limitations for the length of the formatted text that only appears on the iPhone 8 Plus phone?

Prism.Unity.Forms INavigatedAware OnNavigatedTo is not called when navigating multiple pages deep.

$
0
0

Prism.Unity 7.0.0.396 and Xamarin Forms 2.5.0.280555

I just started playing around with Prism with Forms. When navigating 3 deep my third page's viewmodel OnNavigatedTo is not called. Pages 1 and 2 are the same so I am not sure why it doesn't work on Page3.
I can however Navigate from Page 1 to Page 3 and OnNavigatedTo will get called on Page 3. When I try to navigate from page 1 to page2 to page3 it does not.

I have attached a simple repro of my issue in the attached zip file. If anyone can help me figure out what I have done wrong I would greatly appreciate it.

My app.xaml.cs
public partial class App : PrismApplication
{
public App(IPlatformInitializer initializer = null) : base(initializer)
{
}
protected override void OnInitialized()
{
InitializeComponent();
NavigationService.NavigateAsync("HomePage");

    }
    protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<NavigationPage>();
        //Pages
        containerRegistry.RegisterForNavigation<HomePage, HomeViewModel>();
        containerRegistry.RegisterForNavigation<Page1Page, Page1ViewModel>();
        containerRegistry.RegisterForNavigation<Page2Page, Page2ViewModel>();
        containerRegistry.RegisterForNavigation<Page3Page, Page3ViewModel>();
    }

}

public class HomeViewModel : PageViewModelBase, INavigatedAware
{
INavigationService _navigationService;
public ICommand NavigateToActivityManagementPageCommand { get; private set; }
public ICommand NavigateToPage1PageCommand { get; private set; }
public string SideDrawerHeaderIcon { get; }
public string SideDrawerHeaderTitle { get; }
public string SideDrawerSubHeaderTitle { get; }
public HomeViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateToPage1PageCommand = new Command(() => NavigateToPage1Page());
}
private void NavigateToPage1Page()
{
_navigationService.NavigateAsync("Page1Page");
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
throw new NotImplementedException();
}
public void OnNavigatedTo(NavigationParameters parameters)
{
throw new NotImplementedException();
}
}
public class Page1ViewModel : PageViewModelBase, INavigatedAware, IDestructible
{
INavigationService _navigationService;
private string _inputResult;
public string InputResult
{
get { return _inputResult; }
set { SetProperty(ref _inputResult, value); }

    }

    public Page1ViewModel(INavigationService navigationService)
    {
        _navigationService = navigationService;
        NavigateToPage2PageCommand = new Command(NavigateToPage2Page);
    }
    public Command NavigateToPage2PageCommand { get; private set; }
    private void NavigateToPage2Page()
    {
        var selected = 1;
        var parameter = new NavigationParameters();
        parameter.Add("selected", selected);
        _navigationService.NavigateAsync("Page2Page", parameter);
    }
    public void OnNavigatedFrom(NavigationParameters parameters)
    {

    }
    public void OnNavigatedTo(NavigationParameters parameters)
    {

    }
    public void Destroy()
    {

    }
}

public class Page2ViewModel : PageViewModelBase, INavigatedAware, IDestructible
{
INavigationService _navigationService;
public Page2ViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateToPage3PageCommand = new Command(NavigateToSelectedPage);
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
throw new NotImplementedException();
}
public void OnNavigatedTo(NavigationParameters parameters)
{
}
public Command NavigateToPage3PageCommand { get; private set; }
private void NavigateToSelectedPage()
{
//InputResult = "Waiting for result...";
var SelectedItem = 2;
var parameter = new NavigationParameters();

        parameter.Add("selectedItem", SelectedItem);
        _navigationService.NavigateAsync("Page3Page", parameter);
    }

    public void Destroy()
    {

    }
}

public class Page3ViewModel : PageViewModelBase, INavigatedAware ,IDestructible
{
INavigationService _navigationService;
private string _testText;
public string testText
{
get { return _testText; }
set { SetProperty(ref _testText, value); }
}

    public Page3ViewModel(INavigationService navigationService)
    {
        _navigationService = navigationService;
        testText = "Did OnNavigateTo get called?";
    }
    public async void Back()
    {
        await _navigationService.GoBackAsync();
    }
    public void OnNavigatedFrom(NavigationParameters parameters)
    {
        throw new NotImplementedException();
    }
    public void OnNavigatedTo(NavigationParameters parameters)
    {
        var selectedItem = (string)parameters["selectedItem"];
        testText = "OnNavigateTo was called!!";
    }
    public void Destroy()
    {
    }


}

Xamarin.Forms parent BindingContext in DataTemplate in the XAML

$
0
0

After few hours of research, I finally found a solution to my problem. I saw that other people had the same problem : I have a listview with a custom viewcell as datatemplate, the contentpage viewmodel has a shared command "RemoveItem" and I want to invoke it from my custom viewcell.
The original error was : "Xamarin.Forms.Xaml.XamlParseException: No Property of name ElementName found".

In the XAML of my contentpage ("cells" reference the namespace with my customs viewcells):

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Name="cart"/>
<DataTemplate>
    <cells:CartViewCell ParentContext="{Binding BindingContext, Source={x:Reference cart}}"/>
</DataTemplate>

In the class of my custom viewcell:

public partial class CartViewCell : ViewCell
    {
        public CartViewCell()
        {
            InitializeComponent();
        }

        public static readonly BindableProperty ParentContextProperty =
            BindableProperty.Create("ParentContext", typeof(object), typeof(CartViewCell), null, propertyChanged: OnParentContextPropertyChanged);

        public object ParentContext
        {
            get { return GetValue(ParentContextProperty); }
            set { SetValue(ParentContextProperty, value); }
        }

        private static void OnParentContextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
        {
            if (newValue != oldValue && newValue != null)
            {
                (bindable as CartViewCell).ParentContext = newValue;
            }
        }
    }

And in the XAML of my customviewcell:

<ViewCell xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Name="cartCell"><Image.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding ParentContext.RemoveItem, Source={x:Reference cartCell}}" CommandParameter="{Binding .}"/>
</Image.GestureRecognizers>

Sorry if I made some mistakes, french guy :blush:
If you have a better solution I am interested because it's look like a hack for me.

Exception On Resume

$
0
0

Hello,

I'm getting the below exception on Android when resuming an app from clicking on a push notification.

Platform.LayoutRootPage (Xamarin.Forms.Page page, System.Int32 width, System.Int32 height)
System.NullReferenceException: Object reference not set to an instance of an object
Platform.LayoutRootPage (Xamarin.Forms.Page page, System.Int32 width, System.Int32 height)
IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
ViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t,       System.Int32 r, System.Int32 b)
(wrapper dynamic-method) System.Object.44a2ab36-fd3c-4b03-8761-78b3d1b454b7(intptr,intptr,bool,int,int,int,int)

There is a bug filed here:
https://bugzilla.xamarin.com/show_bug.cgi?id=60346

Using FormsApplicationActivity doesn't seem to be a good workaround for me as I need to support material design.

"apksigner.BAT" exited with code 255.

$
0
0

Today I upgraded to the latest Xamarin and Visual Studio and started getting this error when trying to deploy my app to either an android device or an emulator:
C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.0\apksigner.BAT sign --ks \mykeystore.jks --ks-pass pass:somepass --ks-key-alias "\"itscm release\"" --key-pass pass:somepass --min-sdk-version 15 --max-sdk-version 27 bin\Debug\com.test.foo.myapp.apk
The syntax of the command is incorrect.
"apksigner.BAT" exited with code 255.

Does anyone know how to fix it?

Thanks!


How to Hide/Show Searchbar & Toolbar while scrolling the listview in Xamarin forms PCL?

$
0
0

I have a list view, i need to hide toolbar/Navigation bar while scrolling. I have followed this tutorial for Search bar. It is working while appearing disappearing screen is flickering. I need to show/hide like whatsapp. I have attached one sample image. Please help me to achieve this in Xamarin forms PCL.

xamarin.auth vs xamarin.auth.xamarin forms package?

$
0
0

What is the difference between these 2 packages? I cant find any information or sample about xamarin forms named package. does it work on native level and all we should do is in shared project? is there any good sample usage of this package please?

How to implement an Android Service

$
0
0

Hi! I'm trying to periodically check with a web service if a new item has been added to a database. If there's a new item a listview that the user sees should be updated.
I'm using PCL and I have accomplish it creating a new Task with a timer inside. But this only works if the app is open. I want to do the same when the app is closed so the user gets a notification when a new item is added remotely.
I've been doing some research and I found andoid services, the info said that the service will continue, regardless of the app state, until you tell it to stop. But i haven't found many examples in how to implement it.

Here's the code that I had that works only when the app is opened:

 Task.Run(() =>
            {
                Device.StartTimer(TimeSpan.FromSeconds(secs), checkUpdates);
            });

  bool checkUpdates()
          {
            if (isOnline)
            {
                var lastUp= Application.Current.Properties["lastUpdate"] as string;

        //returns true if a new item is added
                if (service.newItem(DateTime.Parse(lastUp)))
                {
                    var itm = service.getNewItem(DateTime.Parse(lastUp));

                    Device.BeginInvokeOnMainThread(() =>
                    {
                            notification.ShowNotification(itm.Title, 1000);
                            listView.Insert(0, itm);
                     }                        
                    });                  
                }
                App.Current.Properties["lastUpdate"] = DateTime.Now.ToString();
            }
            return true;
        }

I'm trying to do the same with an Android service using dependency services, here's what I've got so far:

     public interface IService
        {
            void Start();
        }

      [Service]
        public class DependentService : Service, IService
        {
            public void Start()
            {
                var intent = new Intent(Android.App.Application.Context, typeof(DependentService));
                Android.App.Application.Context.StartService(intent);
            }

            public override IBinder OnBind(Intent intent)
            {
                return null;
            }

            public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
            {
                // From shared code or in your PCL


                return StartCommandResult.NotSticky;
            }
        }

The problem is that I don't know how to implement the code that I had in the timer to the service, can someone please help?

WCF Async calls

$
0
0

Hi guys i have a question regarding WCF datacontracts and and handling larger payloads on the client (Xamarin Forms)
Currently my app reads Configuration data off the server with

            var setupdata2 = await Task.Factory.FromAsync<long, mynamespace.DTO.SetupData2>(
    svc.BeginGetSetupData2,
    svc.EndGetSetupData2,
     App.SiteID,
     null,
     TaskCreationOptions.None);

Where SetupData2 Is a collection of objects is need on the client.

The more payload data i add into these collections the longer i wait.

But it seems unreasonable that i have to wait in excess of 2 minutes for data that i have estimated to be in the region of 5mb of data.
When i debug the UWP app locally on my machine it goes a lot faster but it seems that on a real tablet (Android and Windows) It just takes forever to come back and end the async call to EndGetSetupData2.

What are my options for speeding this up .

And what is a good payload size to start splitting up into multiple requests?

Databound BackgroundColor of Grid in ListView - color keeps reverting on iOS

$
0
0

This is a weird one, and it's got me stumped.

My XAML follows the following pattern:

<ContentView ... >
  <ContentView.Resources>
    <ResourceDictionary>
      <local:ItemColorConverter x:Key="ItemColorConverter" />
    </ResourceDictionary>
  </ContentView.Resources>
  <ContentView.Content>
    <ListView>
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <ViewCell.View>
              <Grid BackgroundColor="{Binding ColorConverterProperty, Converter={StaticResource ItemColorConverter}, Mode=OneWay}">
                (RowDefinitions, ColumnDefinitions, and display elements go here)
              </Grid>
            </ViewCell.View>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </ContentView.Content>
</ContentView>

In my code, I have the following:

public class Item : INotifyPropertyChanged, IComparable<Item>
{
    (fields go here)

    [JsonIgnore]
    public ColorParams ColorConverterProperty
    {
        get
        {
            return new ColorParams(things that the IValueConverter needs to access);
        }
    }
}

My IValueConverter is as follows:

class ItemColorConverter : IValueConverter
{
    private static Color ms_cColor1 = Color.FromRgb(255, 255, 255);
    private static Color ms_cColor2 = Color.FromRgb(192, 16, 0);
    private static Color ms_cColor3 = Color.FromRgb(0, 16, 192);

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        ColorParams cpParams;

        if (value != null && value.GetType() == typeof(ColorParams))
        {
            cpParams = (ColorParams)value;

            if (cpParams.Value1)
            {
                return ms_cColor1;
            }
            else
            {
                if (cpParams.Value2)
                {
                    return ms_cColor2;
                }
                else
                {
                    return ms_cColor3;
                }
            }
        }
        else
        {
            return Color.Transparent;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

This all works great. I can fire the INotifyPropertyChanged for ColorConverterProperty event on the data class, and the ListView row background color changes appropriately. This is what it's supposed to do, and this works on Android and UWP.

However, just recently, it's stopped working on iOS devices. Well, kind of stopped working. The event fires, the ListView line's background color changes, but a fraction of a second later, it changes back to the first color. I've traced out my app, and it doesn't fire the event a second time, and the color converter doesn't get called twice, only once. But the background color still changes back.

The weird thing is, if I scroll the item in question off the screen, then scroll it back on the screen, it has the correct background color again. It's almost like iOS redraws the item on the screen with the old background color, and only redraws the item when it's scrolled back on screen.

Viewing all 77050 articles
Browse latest View live


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