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

Button Click Animations Lag on Very First Click Since App Launch

$
0
0

I'm using the latest release of Xamarin.Forms 3 and I've ran into a very tedious issue. The very first time a button is clicked since the app was started can be terribly laggy in animation. I will click on the button, and a good 2 to 3 seconds later the animation plays. It seems the animation doesn't play until the logic of the event handler has already gone underway.

The amount of lag tends to depend on how much work is being done in the clicked event handler. Even if the method being called is a non-blocking async method. Every click of the button after behaves as intended. This behavior exists on every button until it is clicked for the first time. Even a simple navigation PushAsync will have a delay, but if I press back then that same nav button, it behaves perfectly.

Here's an example of a clicked event handler that causes a lot of lag in the button animation.

    public async void Button_Clicked(object sender, EventArgs e)
        {

            string response = await Foo.GetSomethingOverNetwork();

        }

Stretching a RelativeLayout's height with an expandable StackLayout

$
0
0

Hi,

Here is my code:

<RelativeLayout>
    <BoxView Color="#3498DA" HeightRequest="50" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"/>

    <StackLayout
        RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Factor=0, Property=X, Constant=108}"
        RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Factor=0, Property=Y, Constant=53}"
        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Factor=1, Property=Width, Constant=-118}"
        VerticalOptions="StartAndExpand">

        <Label Text="{Binding Name}" FontSize="18" FontAttributes="Bold"/>
        <Label Text="{Binding Id, StringFormat='ID: {0}'}" FontSize="Micro"/>
    </StackLayout>
</RelativeLayout>

Note: I used a StackLayout in order to get the ID label systematically following the Name label.

This works fine when Name label is shown on 1 line:

But whenever the name is shown on 2 lines, then basically the RelativeLayout is not stretched enough (red borders show how Xamarin computes the height of the RelativeLayout:

Question: How should I handle this properly?

Remark: Using a RelativeLayout because on the left of the labels there is some graphics, similarly to https://developer.xamarin.com/samples/xamarin-forms/UserInterface/BusinessTumble/

Prism and NavigationPage

$
0
0

Hello,

i'm playing around with prism. At the moment, i'm trying to create an app that starts wih a navigation page.

In a 'classic' xamarin.forms app i would do it like this in my App.cs:

public App ()
{
  InitializeComponent();

  var myMainPage = new MyMainPage();
  var navPage = new NavigationPage(myMainPage);

  MainPage = navPage;
}

I'm struggeling to do this with prism.

@BrianLagunas can you provide an example on how to start with a navigation page using prism?

Audio slider: how to detect when user changes its position through ViewModel?

$
0
0

I've been trying to create an audio player which uses a slider to control its time. Thus, when user changes the slider position, the player seeks for that position on audio. In my case, I use ViewModel, so I'd like to do all control through ViewModel and not on View (codebehind).

I also use XAML, and my slider is it:

<Slider x:Name="sliderAudio"
        Minimum="0" Maximum="{Binding Duration}"
        Value="{Binding AudioCurrentProgress}" />

As you can see, there are two binding values: Duration, which is the duration time of the audio, and AudioCurrentProgress, which returns me the current position of the audio that is playing (or not).

Thus, I use AudioCurrentProgress for two things: 1) control the slider position and 2) play the audio exactly where the user wants.
That I already can do it! But only in a situation: if user stops the player and touch "play" again.

What I'd want to do is:
How can I detect when user changes the slider position when player IS PLAYING?

The problem is: AudioCurrentProgress changes its value everytime when player is playing.
So, I don't know it slider changes the position if user moved it or it it changes because player is playing. You know what I meant?

Helpful Shared Project Image information

$
0
0

Fellow devs,

I just wanted to share some information in case it is helpful to you. I am exploring the Shared Projects approach for Xamarin.Forms. In my app, I wanted to be able to put images into the shared project and load them into my UI as needed (ie logos, etc.). This was not obvious to me at all.

I found a great bit of information here which provided most of the clues: link

Important information is this:
1. Images must be marked as an embedded resource (if in shared project)
2. In Shared Projects, the path to the image location translates at run-time to <Assembly Name> + . + imagename (note, this is not the same for PCLs)
3. In order to have shared code find the right image location at run-time, I did the following inside of my view class:

private string _baseResource;
public string BaseResource
{
  get
  {
    return _baseResource ?? (_baseResource = Assembly.GetExecutingAssembly().FullName.Split(',').FirstOrDefault());
  }
}

private ImageSource PlatformImageResource(string resource)
{
  return ImageSource.FromResource(BaseResource + "." + resource);
}

This allowed for me to load the image more easily and have it be platform specific, as follows:

  var logo = new Image
  {
    Source = PlatformImageResource("app_header_logo.jpg")
  };

If there's an easier way, I'd love to hear about it!

I hope this helps others : )

Thanks!
Michael

Using Embedded Images via binding

$
0
0

Hi,

I'm new to Xamarin Forms only started a couple of weeks ago coming from a WPF / MVVM background. I have a MasterDetailPage all working without icons so I am trying to 'bind' embedded images.

So in my MenuView XAML page, I have the following:-

  <ListView x:Name="lvMenu" VerticalOptions="FillAndExpand" SeparatorVisibility="None" ItemsSource="{Binding Menu}">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" />
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

The Menu is just a list of MenuItems that have TargetType, Title and IconSource properties. My IconSource contains the filename of the image, ie: cog.png

The following works and does show the image (albeit the same image for all the menu options):

<ImageCell Text="{Binding Title}" ImageSource="{local:ImageResource Touchretail.Trims.Mobile.Images.cog.png}" />

So I'm pretty sure it is achievable. What I would like to do is just replace the cog.png part with the TargetType from the Menu object. Effectively - I'm trying to get to:

<ImageCell Text="{Binding Title}" ImageSource="{local:ImageResource Touchretail.Trims.Mobile.Images.{Binding IconSource}}" /> 

but obviously this would not work.... How can I achieve the desired result?

Images with databinding via XAML

$
0
0

I am able to display images successfully, but it fails when I try to do it with data binding in a XAML ListView.

I have tried it a couple ways.

1

Image Source="{Binding ImageResourcePath}"

I know the object is getting pulled correctly because I have a label immediately near that pulls another property ("{Binding Street}") successfully.

2

ImageCell Text="{Binding Street}" ImageSource="{Binding ImageResourcePath}"

Both of these approaches show text information just fine, but the image is gone.

I can see the image resources have loaded from a assembly.GetManifestResourceNames check I do. I copied the paths directly from that output to the ImageResourcePath.

I have even put static paths that I can see working (not in the ListView) into the ImageResourcePath, but this shows as blank also.

I have tried switching out the images that work with the databinding images as well. Still blank.

Edit:

These are embedded assembly images

XAML Label Text: Binding + DynamicResource (String Format?)

$
0
0

Hello,

is there a way to bind the Text Property (in XAML) of a Label to a Binding + DynamicResource? Maybe with string format?

for example I tried something like this:
<Label Text="{DynamicResource resource, Binding binding, StringFormat='Resource: {0} and Binding: {1}"} />
But one cannot declare a binding if a dynamic resource is set, same problem if trying it vice versa (eg. no dynamicresource if binding already set)

  • or with a value converter that returns the binding string to "binding string + dynamic resource"? (Creating a valueconverter for this seems too overwhelming)
  • in code this might work with string.Format(...)

Xamarin Forms - Get path of embedded file

$
0
0

I'm trying from hours/days to get a file which is placed into the PCL part

enter image description here

I saw some examples which using BaseURL but I want to make something cross platform and I can't found how to implement it onto UWP..

So I'm trying to get my local file's URL. For Images, I'm using ImageSource.FromResource("Gif.example.gif") but it doesn't work..

I also tried GifSource = new Uri(ImageSource.FromResource("Gif.example.gif").ToString()); but.. Nothing !

There is my custom control:

public class Gif : WebView
{
    public static readonly BindableProperty GifSourceProperty =
        BindableProperty.Create(nameof(Uri), typeof(string), typeof(Gif), null);
    public string GifSource
    {
        get { return (string)GetValue(GifSourceProperty); }
        set { SetValue(GifSourceProperty, value); }
    }

    Action<string> action;
    public void RegisterAction(Action<string> callback)
    {
        action = callback;
    }

    public void Cleanup()
    {
        action = null;
    }

    public void InvokeAction(string data)
    {
        if (action == null || data == null)
        {
            return;
        }
        action.Invoke(data);
    }
}

Thank for help !

The Certificate for this server is invalid, How to use https in xamarin forms

$
0
0

I am having an issue when communicating with back-end web server with https. It works fine with HTTP. My
app consumed WCF web service and hosted on IIS. I've used HttpClient in code.
My server has a self-signed certificate. I have made the below changes to my source code.

  1. Updated the infor.plist as given below.
    NSAppTransportSecurity
    NSAllowsArbitraryLoads
    NSExceptionDomains
    ip address without port number
    NSExceptionMinimumTLSVersion
    TLSv1.0NSExceptionRequiresForwardSecrecy
    NSExceptionAllowsInsecureHTTPLoads
    NSIncludesSubdomains

  2. Added below code to appdelegate class in iOS project
    ServicePointManager
    .ServerCertificateValidationCallback += (sender, cert, chain,
    sslPolicyErrors) => true;

I also get an error message "Your connection is not private" when the API is browsed. I can continue with an error. but I can not access the resource (backend data) through web service, does not give me any result. it works fine with HTTP.
Does anyone know how to use HTTP client with https in cross-platform development? What are alternative methods to use https? How can I ignore the SSL error?

Xamarin Forms Video Compression

$
0
0

hi,

is there any cross platform plugins available for video compression ?

any help will be appreciated.

Tabbed page in contentpage

$
0
0

I want to have a tabbed page in contentpage, i have attached a image on what i mean. How should i continue? i have already implemented the tabs to change pages but have problem to get tabbs in contentpage to work!

[Prism] Switch tab without actually using navigation

$
0
0

I am using a Tabbed page, and I need to switch tabs programmatically, for example by clicking on a button.

I need to simulate the swipe action, same as if you swiped to a different tab with the finger.
I am wondering if there is a way to do it with prism.

I don't want to use "Navigation/MyTabbedPage?SelectedTab=Dashboard" because it reloads the page completely.

Any ideas?
Tagging @BrianLagunas just in case :)

How to implement a login with facial recognition?

$
0
0

Hi guys,

Do you know a way to implement a login with facial recognition in Xamarin Forms?
I´m trying show a stream from webcam emulating phone´s cams with Nuget Xam.Plugin.Media but I couldn´t get nothing.

Greetings.

RTSP player in xamarin forms

$
0
0

Hi Friends,
i am trying to create a xamarin application in that i need to implement live stream using RTSP protocol from a device. can any one suggest me how can we achieve that with xamarin forms.
Advance Thanks,
Vijay.A


Self host API on mobile app using Xamarin Forms

$
0
0

Is that possible to self host API on mobile(Xamarin.Forms Android/Ios), which can be called locally(for example in one Wi-Fi network)?

PanGestureRecognizer not working in Android (Xamarin Forms)

$
0
0

I recently created a custom control that contains two child controls within a Grid. I added a PanGestureRecognizer to the custom control to move the child controls through the Y axis when the PanUpdated event fires. This works fine in iOS, but Android does not fire the PanUpdated event.

To investigate I looked at the example of how to do pan gestures here: https://developer.xamarin.com/guides/xamarin-forms/user-interface/gestures/pan/

This example works on Android, but as soon as you change the Image inside the PanContainer to something else, say a Grid containing some other controls, then PanUpdated stops firing. As I mentioned this all works well on iOS.

I'm currently using XF 2.3.3.180

Can anyone offer any help or guidance on how to get the pan gesture working in Android?

Using {Binding .} with value converters

$
0
0

Hi,
I am writing an application using a ListView:

<ListView ItemsSource="{Binding Places}">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <Grid>
                <Grid.RowDefinitions>
                  <RowDefinition Height="Auto"/>
                  <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="*"/>
                  <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <Label TextColor="White" Text="{Binding Name}" Grid.ColumnSpan="2" FontSize="20" />

                <Label TextColor="White" Text="{Binding Path=. , Converter={StaticResource todayConverter}}" Grid.Row="1" />
                <Label TextColor="White" Text="{Binding Path=. , Converter={StaticResource distanceConverter}}" Grid.Row="1" XAlign="End" Grid.Column="1"/>
              </Grid>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>

I need to pass the whole BindingContext object to my converters but in the converters code is value object set to null:

    class DistanceConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                //value is set to null
                if (value == null) Debug.WriteLine("value is null");

                PizzaPlace i = value as PizzaPlace;

                if (i.DistanceTo < 500)
                {
                    return String.Format("{0} (cca {1:0} m)", i.City, i.DistanceTo);
                }
                return String.Format("{0} (cca {1:0.0} km)", i.City, i.DistanceTo / 1000);
            }

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

How can I pass whole BindingContext objects to value converters?

I keep having an error about nuget System.IO.FileNotFoundException

$
0
0

package even if I don't have it, searched the whole solution I have a higher version but 2.2.1.0 no, alose tried to clean everything but no luck, restarted VS no luck

Severity Code Description Project File Line Suppression State Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Plugin.Permissions.Abstractions, Version=2.2.1.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile? File name: 'Plugin.Permissions.Abstractions.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel) at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver)

Login sample

$
0
0

Hi can anyone help how to create a login using masterdetailpage

Viewing all 91519 articles
Browse latest View live


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