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

Binding to Custom Behavior Bindable Property in XAML

$
0
0

I'm trying to follow along with the information here about making a custom max length behavior: https://xamarinhelp.com/xamarin-forms-triggers-behaviors-effects/

public class MaxLengthCheckValidator: Behavior<Entry>
{

    public static readonly BindableProperty IsValidProperty = BindableProperty.Create("IsValid", typeof(bool), typeof(MaxLengthCheckValidator), false);
    public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create("MaxLength", typeof(int), typeof(MaxLengthCheckValidator), 0);

    public int MaxLength
    {
       get { return (int)GetValue(MaxLengthProperty); }
       set { SetValue(MaxLengthProperty, value); }
    }

    public bool IsValid
    {
       get { return (bool)GetValue(IsValidProperty); }
       set { SetValue(IsValidProperty, value); }
    }

    protected override void OnAttachedTo(Entry bindable)
    {
       bindable.TextChanged += bindable_TextChanged;
    }

    private void bindable_TextChanged(object sender, TextChangedEventArgs e)
    {
       IsValid = e.NewTextValue?.Length >= MinLength;
    }

    protected override void OnDetachingFrom(Entry bindable)
    {
       bindable.TextChanged -= bindable_TextChanged;
    }
 }

But I'm kind of confused about how to bind to the new BindableProperty in XAML.

    // Add to Page attributes
    xmlns:behavior="clr-namespace:Mobile.Behavior"

<Entry Text="{Binding EntryField}">
    <Entry.Behaviors>
        <behavior:MaxLengthCheckValidator MaxLength="10" IsValid="{Binding Source={x:Reference this}, BindingContext.IsUsernameValid, Mode=OneWayToSource}" />
    </Entry.Behaviors>
</Entry>

I don't understand the part about the IsValid binding.

I am new to Xamarin.Forms and I'm still struggling with bindings a bit, and this is confusing me - it looks to me like maybe it's connecting with the entry text field in the source (with "x:Reference this"), but what is the "BindingContext.IsUsernameValid" supposed to represent?

I thought the BindingContext is the parent object and the binding should connect to the property/child of that object, but I don't understand how it's being used here with a behavior - what is that object supposed to be? There's no complete sample in GitHub, so I can't tell if that was supposed to be the "IsValid" property instead (there are other errors in here - see ">= MinLength"), or if I'm missing part of the code, or what.

I could use some help figuring out the correct structure of the binding and would really appreciate some clarification.


Viewing a presentation in Xamarin.Forms

$
0
0

Hello, Is it possible to play a presentation in Xamarin.Forms (or Xamarin.Android)?

UnifiedMaps - A platform independent map implementation for Xamarin.Forms.

$
0
0

I just wanted to promote our Xamarin.Forms Maps implementation. It was developed with the MVVM pattern in mind and therefore supports Commands and Data-Binding for all features.

It supports various things such as:

  • iOS (Apple Maps) and Android (Google Maps)
  • Map Type (Street, Sattelite, Hybrid)
  • Custom Markers
  • Draw Lines between Points
  • Autofit all Annotations
  • Hide Native Maps Controls

The code is Open Source and on Github with fully automated builds and push to NuGet for new versions.

https://github.com/fiveninedigital/UnifiedMaps
https://nuget.org/packages/UnifiedMaps/

Wait for Device.BeginInvokeOnMainThread

$
0
0

Hello,

I have an interface IPicture which I uses on Android and iOS.

I implemented with dependecy service a way to save a photo in device.

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using UIKit;
using System.IO;
using System.Threading.Tasks;
using System;
using Xamarin.Forms;


[assembly: Xamarin.Forms.Dependency(typeof(MyApp.iOS.Picture_iOS))]

namespace MyApp.iOS
{
    public class Picture_iOS: IPicture
    {
        public Int16 SavePictureToDisk(string filename, byte[] imageData)
        {
            var chartImage = new UIImage (NSData.FromArray (imageData));
            Int16 response = 0;


            Device.BeginInvokeOnMainThread (() => {


                chartImage.SaveToPhotosAlbum ((image, error) => {
                    //you can retrieve the saved UI Image as well if needed using
                    //var i = image as UIImage;
                    if (error != null) {
                        Console.WriteLine (error.ToString ());
                        response = 0;
                    } else
                        response = 1;
                });
            });

            return response;
        }
    }
}

My problem is that I need it to return a Int16 as response... but just after the Device.BeginInvokeOnMainThread runs...

I can't use await because it is void...

How I can do that?

No Checkboxes or Radio Buttons

$
0
0

Can someone explain to me why Xamarin Forms does not have checkboxes or radio buttons implemented? I feel like these two are the most basic controls that Android and iOS platforms have natively. It's pretty baffling to see that Xamarin Forms doesn't have something like this out of the box.

How to pass parameters to tapped event

$
0
0

Hi,

I am using the following Xamarin Code

<ListView ItemsSource="{Binding UserGroups}" RowHeight="66">
          <ListView.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <StackLayout Orientation="Horizontal" Spacing="10" Padding="10,10,10,10" TranslationX="10">
                  <Label
                    Text="{Binding Name}"
                    VerticalOptions="CenterAndExpand"  >
                    <Label.GestureRecognizers>
                      <TapGestureRecognizer  NumberOfTapsRequired="2" Tapped="OnEditGroupClicked" CommandParameter="{Binding Name}" />
                    </Label.GestureRecognizers>
                  </Label>
                 </StackLayout>
              </ViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
    </ListView>

Tapped event is firing, but sender and args are getting as unknown identifier, I am not able to figure out the issue

On Code behind file,

async void OnEditGroupClicked(object sender, EventArgs args)
{
// I want to access the Name
}

and sender and args are getting as unknown identifier

Can someone guide me the correct way to pass the parameter to tapped event

Thanks in Advance

Pop Display Alert/ Message from ViewModel

$
0
0

Guys.

How do i invoke/ call display alert/show message once my program did some logic in ViewModel (MVVM)?

E.g

  1. Login Form --> Enter Login Data ---> Click Login Button---> Bind button command to LoginViewModel

Lets say the program done the login validation..how do i send back the login result to Login Page (assuming if login failed) ?

Upgade to Xamarin.Forms3 throws exception Support.Core.UI.26.0.2 not present when 27.0.2 exists

$
0
0

Have an existing simple project - 1 view, a couple ViewModels and a few styles.
With XF2.5.blah.blah it builds fine.
I figured it would be a good test subject for upgrading to XF3
There were the typical issues with nugets. Resolved them by clearing the Nuget cache in Visual Studio and nuking the bin and obj directories, then restarting Visual Studio.

One problem remains. Xamarin.Android.Support.Core.UI version 27.0.2 is installed. When I build however VS complains that version 26.0.2 was not found
Really? What the?

Anyone else encounter this when upgrading to XF3?


Logging from the .Net Standard library

$
0
0
Is there a built in way or a package to use for common logging within the .Net Standard library? I was using one package from Nuget but it has since been unlisted.

Bizarro World Xamarin.Forms errors...

$
0
0

I was working on a Xamarin.Forms project for weeks - everything compiled and I was able to distribute. The last things which happened as of 05/20, were 1) a Windows 10 update occurred, and 2) I did a VS 2017 update.

Now the entire project has this "type or namespace 'system'..." error on everything. This is happening 1) upon creating a brand new project and 2) before doing anything - even compiling. Just opening the "App.xaml.cs" file after a few seconds highlights all these things in red in the IDE

A screenshot of partial list of the "App.xaml.cs" file and the errors is here:

https://drive.google.com/open?id=17y-8tfJ5eJmp-JfBF8h0QlezioUHgSpz

I've lost several days now fighting to get the project back to where it was - stuck in Seattle!

Would appreciate any help!

In the Toasts.Forms.Plugin, how can I change the background color to the toast?

$
0
0

Hi!

I'm using this plugin: https://github.com/EgorBo/Toasts.Forms.Plugin
With the version 2.0.4

I need change the backgroundcolor but I don't find how.

I see that in the first param of Notify, I pass a enum ToastNotificationType, this enum have a field called custom, but a don't find how I can use it.

Any idea how can to do it?

Thanks :smile:

Regards!

Bug: RelativeLayout Not Obeying Padding or LayoutOptions

$
0
0

Xamarin Team,

I have been trying to use RelativeLayout for my application, and I've also been trying to abstract the Padding and LayoutOptions for this layout to an application-level ResourceDictionary.

I've tried simplifying this down to a very simple case where I have the following in my application-level ResourceDictionary:
`<Application.Resources>


  <LayoutOptions x:Key="RelativeLayout_HorizontalOptions"
                 Alignment="End"
                 Expands="True" />

  <LayoutOptions x:Key="RelativeLayout_VerticalOptions"
    Alignment="Start"
    Expands="False" />
</ResourceDictionary>

</Application.Resources>`

And I have the following markup in my RelativeLayout:
<RelativeLayout Padding="50" BackgroundColor="Red" HorizontalOptions="{StaticResource RelativeLayout_HorizontalOptions}" VerticalOptions="{StaticResource RelativeLayout_VerticalOptions}"> <Label Text="Test Label" /> </RelativeLayout>

When the layout is a RelativeLayout the padding is not obeyed at all, but the Alignment for the LayoutOptions is obeyed, while the Expands Boolean is not obeyed. I originally thought this may be because of an inability to parse a String to a Boolean, but this is not the case, as far as I can tell, since the example here shows LayoutOptions done in exactly this way, and the Boolean structure documentation clearly states that the String representation of a Boolean is either "True" or "False", in order for it to be parse-able.

Switching the RelativeLayout to a StackLayout causes the Padding StaticResource definition to be obeyed, but, just as in the case of RelativeLayout, the StackLayout only obeys the Alignment property of the LayoutOptions StaticResource and not the Expands property.

Please look into this bug, since it is at such a fundamental level.

Is there a way to render the Zxing ScannerPage in Xaml?

$
0
0

I'm using the MVVM approach to make a small scanner app. I have a startPage.Xaml with one button binded to a command in the viewModel that opens my scannerPage.Xaml On the scannerPage I have just a simple footer, and want the scanner object to fill the rest of the page. However, when I add the scanner object to my stackPanel I get the following exception: "System.MissingMethodException: Default constructor not found for type ZXing.Net.Mobile.Forms.ZXingScannerPage". I'll list my xaml code below. Any help will be much appreciated. Thanks

<?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:forms="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
             xmlns:custom="using:MobiNative_Forms.Views"
             x:Class="MobiNative_Forms.Views.BarcodePage"
             BackgroundColor="Transparent">
  <ContentPage.Content>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="8.5*" />
        <RowDefinition Height="1.5*" />
      </Grid.RowDefinitions>
      <StackLayout x:Name="layout2" Grid.Row="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <forms:ZXingScannerPage></forms:ZXingScannerPage>
      </StackLayout>
      <Label Grid.Row="1" Text="MOBI" FontSize="Large" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="Blue"/>
    </Grid>
  </ContentPage.Content>
</ContentPage>

MediaPlayer Issue _mediaPlayer.Prepared += (sender, args) => {

$
0
0

I have an Issue in Android version(8.0 and above),in all other versions it's working fine,i have posted my code please check and help me in this case thank you

public void Play(string pathToAudioFile)
{
if (_mediaPlayer != null)
{
_mediaPlayer.Completion -= MediaPlayer_Completion;
_mediaPlayer.Stop();
}

        if (pathToAudioFile != null)
        {
            if (_mediaPlayer == null)
            {
                _mediaPlayer = new MediaPlayer();

                _mediaPlayer.Prepared += (sender, args) =>
                {
                    _mediaPlayer.Start();
                    _mediaPlayer.Completion += MediaPlayer_Completion;
                };**//it's not firing in oreo **
            }

            _mediaPlayer.Reset();
            //_mediaPlayer.SetVolume (1.0f, 1.0f);

            _mediaPlayer.SetDataSource(pathToAudioFile);
            _mediaPlayer.Start();
            _mediaPlayer.PrepareAsync();
        }
    }

How to make part of string bold in code behind in xamarin forms?

$
0
0
Hello team,

I am using below logic in code behind to make the part of string bold in xamarin forms but its not working

S= "Hello world"+{0}+"."

The value inside this 0 should be bold.

Please help me with the correct logic, i have tried a lot but no luck.

Scrollable list

$
0
0

HI Xamarin Forum

How to make a list that is scrollable but on top of it is a grid with a 3 column just like table of html.

How can i get the device date time?

$
0
0

Hi,
I have a issue.

When I change the device date time and run the App, the code DateTime.Now don't return the new date, it returns the old date.
How can I get the device date time?

Questions on periodic background tasks for Android and iOS

$
0
0

Hi all,

I am planning to start my first Xamarin.Forms project soon. I have been working with UWP for a long time, and the background tasks are pretty awesome.

To me, it's not entirely clear if the following use case would be achievable:

  • Run a background task (meaning that the app is NOT open) every ~15 minutes.
  • Fetch data from a remote server (small JSON file).
  • Some logic that will check the data and show a notification to the user in some cases.
  • Ideally also update the content of the app's widget.

I saw some documentation for Xamarin.Android related to Services, but for iOS it's unclear if this would be achievable.

Can someone point me to the correct documentation, or if the above scenario is possible for both iOS and Android?

Kind regards,
Niels

Xamarin Live Play

$
0
0

Hi
I am new in the forum, I need your help. I do not know how to install the xamarin live play in my iphone, I not know the procedure, I want to test the visual studio 2015 with my iphone 6. I read that I need instal firth the app testflightapp but the code was not generated, please I hope you can help me, thanks.

Crash on startup in Xamarin.iOS

$
0
0

When I debug the app in the emulator it works fine, but when I upload it to the App Store it doesn't work... I'm using AppCenter for analytics and crashes features, but when the app crash, the AppCenter doesn't collect the data to show me in the portal (I suppose that the crash happen before the AppCenter starts).

Any ideas?

Thanks!

Viewing all 91519 articles
Browse latest View live


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