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

Data binding for the Items Source of a Picker control

$
0
0

So, the Picker control doesn't have data binding to item source capability? Am I the only one who thinks that this is a major oversight? I had to implement a message pattern to notify UI that the data for the picker had been loaded so that it could populate the Items collection.


Binding to Picker Items

$
0
0

Hi,

I believe it is not possible to Bind in XAML to the Items property of the Picker control.

If this is the case, which is the best approach to populate the Items collection from a ViewModel collection?

I believe it is possible to call the Add method against the Items collection however how might I reference the Picker, as defined in the XAML, in the code behind?

I have tried FindByName however I don't seem to be able to set the Name of the Picker control.

Thanks

Paul Diston

Has anyone made a Picker with bindable items?

$
0
0

Has anyone extended the Picker control to expose a Bindable property ItemSource that when set, goes and adds the items to the Items property?

Is it that simple or am I being naive?

Has anyone managed to do this?

(PS. why isn't this is the framework yet, every time I have to add the items in code behind a little part of me dies)

Bindable Picker in a Cell

$
0
0

I have a custom control called BindablePicker and I display it in a ViewCell like this:

<ViewCell>
    <StackLayout Orientation="Horizontal" Padding="15, 5, 15, 5">
        <Label Text="ViewCell" YAlign="Center" />
        <controls:BindablePicker ItemsSource="{Binding BitsPerPixelValues}" SelectedItem="{Binding BitsPerPixel}" HorizontalOptions="EndAndExpand" />
    </StackLayout>
</ViewCell>

This works and looks fine.

Now I want to refactor that to a BindablePickerCell class. I changed the xaml to this:

<cells:BindablePickerCell
    Label="BindablePickerCell"
    ItemsSource="{Binding BitsPerPixelValues}"
    SelectedItem="{Binding BitsPerPixel}" />

And added a BindablePickerCell with this code:

public class BindablePickerCell : ViewCell
{
    #region Properties
    ...
    #endregion

    Label label;
    BindablePicker picker;

    public BindablePickerCell()
    {
        label = new Label { YAlign = TextAlignment.Center, BindingContext = this };
        label.SetBinding(Xamarin.Forms.Label.TextProperty, (BindablePickerCell c) => c.Label, BindingMode.OneWay);

        picker = new BindablePicker { HorizontalOptions = LayoutOptions.EndAndExpand, BindingContext = this };
        picker.SetBinding(BindablePicker.ItemsSourceProperty, (BindablePickerCell c) => c.ItemsSource, BindingMode.OneWay);
        picker.SetBinding(BindablePicker.SelectedItemProperty, (BindablePickerCell c) => c.SelectedItem, BindingMode.TwoWay);

        View = new StackLayout()
        {
            Orientation = StackOrientation.Horizontal,
            Padding = new Thickness(15, 5),
            Children = { label, picker }
        };
    }
}

But now, the HorizontalOptions = LayoutOptions.EndAndExpand on the picker does not work anymore on iOS. The Picker is displayed too narrow. In the hardcopy you can see the BindablePickerCell followed by the old ViewCell.

What am I doing wrong?

Custom Bindable picker selectedItem not firing

$
0
0

I have a custom BindablePicker which inherits from picker, having copied some code in a previous post. However I am finding that when an item is selected, my property is not being updated.

BINDABLEPICKER
public class BindablePicker : Picker
{
#region Fields

        //Bindable property for the items source
        public static readonly BindableProperty ItemsSourceProperty =
            BindableProperty.Create<BindablePicker, IEnumerable>(p => p.ItemsSource, null, propertyChanged: OnItemsSourcePropertyChanged);

        //Bindable property for the selected item
        //public static readonly BindableProperty SelectedItemProperty =
        //  BindableProperty.Create<BindablePicker, object>(p => p.SelectedItem, null, BindingMode.TwoWay, propertyChanged: OnSelectedItemPropertyChanged);

        public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem", typeof(object), typeof(BindablePicker), null, BindingMode.TwoWay, null, propertyChanged:OnSelectedItemPropertyChanged);

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the items source.
        /// </summary>
        /// <value>
        /// The items source.
        /// </value>
        public IEnumerable ItemsSource
        {
            get { return (IEnumerable)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }

        /// <summary>
        /// Gets or sets the selected item.
        /// </summary>
        /// <value>
        /// The selected item.
        /// </value>
        public object SelectedItem
        {
            get { return GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Called when [items source property changed].
        /// </summary>
        /// <param name="bindable">The bindable.</param>
        /// <param name="value">The value.</param>
        /// <param name="newValue">The new value.</param>
        private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable value, IEnumerable newValue)
        {
            var picker = (BindablePicker)bindable;
            var notifyCollection = newValue as INotifyCollectionChanged;
            if (notifyCollection != null)
            {
                notifyCollection.CollectionChanged += (sender, args) =>
                {
                    if (args.NewItems != null)
                    {
                        foreach (var newItem in args.NewItems)
                        {
                            picker.Items.Add((newItem ?? "").ToString());
                        }
                    }
                    if (args.OldItems != null)
                    {
                        foreach (var oldItem in args.OldItems)
                        {
                            picker.Items.Remove((oldItem ?? "").ToString());
                        }
                    }
                };
            }

            if (newValue == null)
                return;

            picker.Items.Clear();

            foreach (var item in newValue)
                picker.Items.Add((item ?? "").ToString());
        }

        /// <summary>
        /// Called when [selected item property changed].
        /// </summary>
        /// <param name="bindable">The bindable.</param>
        /// <param name="value">The value.</param>
        /// <param name="newValue">The new value.</param>
        private static void OnSelectedItemPropertyChanged(BindableObject bindable, object value, object newValue)
        {
            var picker = (BindablePicker)bindable;
            if (picker.ItemsSource != null)
                picker.SelectedIndex = picker.ItemsSource.IndexOf(picker.SelectedItem);
        }



        #endregion
    }
}

VIEW
<local:BindablePicker Title="Relationship" ItemsSource="{Binding PersonLinkTypes}" SelectedItem="{Binding SelectedLinkType}"/>

VIEWMODEL

            private string _selectedLinkType;
                public string SelectedLinkType
                {
                    get
                    {
                        return _selectedLinkType;
                    }
                    set
                    {
                        _selectedLinkType = value;
                    }
                }

        private IEnumerable<string> _PersonLinkTypes;
        public IEnumerable<string> PersonLinkTypes
        {
            get
            {
                return _PersonLinkTypes;
            }
            set
            {
                _PersonLinkTypes = value;
                OnPropertyChanged("PersonLinkTypes");
            }
        }

Binding to constants not working any more in Xamarin Forms 2.3.3

$
0
0

Hi

Below XAML fragment does not work any more and is giving a compilation error

<Image Source="{x:Static helpers:MyConstants.InfoIcon}" />

Compilation error is :

No property, bindable property, or event found for 'Source'

I rolled back to previous version (2.3.2) and the error goes away.

Facing the same issue when trying to see the Icon property of ToolbarItem as well.

Would appreciate any insight / workaround !

Regards & thanks
Kapil

Xamarin.Forms Bindable Picker

$
0
0

If anyone wonders how to make a Bindable Picker, here's the code:

`

public class BindablePicker : Picker
{
    #region Fields

    //Bindable property for the items source
    public static readonly BindableProperty ItemsSourceProperty =
        BindableProperty.Create<BindablePicker, IEnumerable>(p => p.ItemsSource, null, propertyChanged: OnItemsSourcePropertyChanged);

    //Bindable property for the selected item
    public static readonly BindableProperty SelectedItemProperty =
        BindableProperty.Create<BindablePicker, object>(p => p.SelectedItem, null, BindingMode.TwoWay, propertyChanged: OnSelectedItemPropertyChanged);

    #endregion

    #region Properties

    /// <summary>
    /// Gets or sets the items source.
    /// </summary>
    /// <value>
    /// The items source.
    /// </value>
    public IEnumerable ItemsSource
    {
        get { return (IEnumerable)GetValue(ItemsSourceProperty); }
        set { SetValue(ItemsSourceProperty, value); }
    }

    /// <summary>
    /// Gets or sets the selected item.
    /// </summary>
    /// <value>
    /// The selected item.
    /// </value>
    public object SelectedItem
    {
        get { return GetValue(SelectedItemProperty); }
        set { SetValue(SelectedItemProperty, value); }
    }

    #endregion

    #region Methods

    /// <summary>
    /// Called when [items source property changed].
    /// </summary>
    /// <param name="bindable">The bindable.</param>
    /// <param name="value">The value.</param>
    /// <param name="newValue">The new value.</param>
    private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable value, IEnumerable newValue)
    {
        var picker = (BindablePicker)bindable;
        var notifyCollection = newValue as INotifyCollectionChanged;
        if (notifyCollection != null)
        {
            notifyCollection.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    foreach (var newItem in args.NewItems)
                    {
                        picker.Items.Add((newItem ?? "").ToString());
                    }
                }
                if (args.OldItems != null)
                {
                    foreach (var oldItem in args.OldItems)
                    {
                        picker.Items.Remove((oldItem ?? "").ToString());
                    }
                }
            };
        }

        if (newValue == null)
            return;

        picker.Items.Clear();

        foreach (var item in newValue)
            picker.Items.Add((item ?? "").ToString());
    }

    /// <summary>
    /// Called when [selected item property changed].
    /// </summary>
    /// <param name="bindable">The bindable.</param>
    /// <param name="value">The value.</param>
    /// <param name="newValue">The new value.</param>
    private static void OnSelectedItemPropertyChanged(BindableObject bindable, object value, object newValue)
    {
        var picker = (BindablePicker)bindable;
        if (picker.ItemsSource != null)
            picker.SelectedIndex = picker.ItemsSource.IndexOf(picker.SelectedItem);
    }

    #endregion
}

`

Usage is pretty straight forward..:

<local:BindablePicker ItemsSource="{Binding Cats}" SelectedItem="{Binding SelectedCat}"/>

It would've been nice that the Xamarin.Forms.Picker already had this functionality, maybe we'll see it in a next update...

Any questions, comments, or contributions are welcome :)

Navigation Bar Transparent

$
0
0

Hello everyone I am trying to make transparent the navigation bar, I searched on the forum and on intenrnet, I tried all the examples but does not work = (, any suggestions or example?


Add PDF attachment to e-mail message using MailKit

$
0
0

Dear all,

I find myself rather stuck on what should be a trivial issue.

I am trying to send an e-mail from my app with a PDF document as an attachment.

I am generating the PdfDocument using the API provided by Syncfusion. To send the messages, I am using MailKit. When sending a plain message everything works fine, however I cannot add an attachment to the message. I have tried various ways but I was unable to accomplish this rather simple task.

In the MailKit documentation it states nothing about adding attachments, only reading them and downloading them. This is a rather crucial function to my app.

Did any of you manage to send e-mail from your apps containing attachments?

DataPages CustomControl example

local folder

$
0
0

hello
i'm new in xamarin
i create xamarin form (shared) project to use it in our work
my application support offline mapping use
application downloaded files and saved into (storage/emulated/0/SmartMaps) for android

and now ill configure the app to work on ios
how i can create and access public folder (SmartMaps) to save my data in it in android and ios

i used Environment.GetFolderPath(Environment.SpecialFolder.Personal);
put it return path like this /data/user/0/MyApp/files/ and downloaded data not found

How to Resolve Exception: Cannot create an instance of "WindowsPage".

$
0
0

Hey everyone,

Brand new to Xamarin forms here and trying to get started in cross platform app development using the package. However right out of the gate I seem to be running into an issue that has been asked a few times elsewhere but I haven't really seen an actual response on. Currently I'm trying to work on the UWP / Universal Windows / Windows 10 User Interface in a Portable Forms / PCL setup.

It's the Cannot create an instance of WindowsPage error message in the Microsoft Visual Studio 2015 Xaml designer. I'm following the guide at https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/ so I added the line for "xmlns:forms="using:Xamarin.Forms.Platform.UWP" the xaml file before changing the page tag from Page to forms:WindowsPage thus referencing the xamarin forms package. I did update all the NuGet packages to the latest version. Xamarin forms is something like 2.2 at the moment.

I initially installed the defaults for the VS2015 Xamarin package and I just tried modifying that installation with every extra component included so I don't think I'm missing anything there. I believe Xamarin is installed properly since it shows up in the Help -> Xamarin menu and I can choose new solutions out of the Xamarin forms package but I'm not sure what could be causing the issue.

Here's the XAML code

<forms:WindowsPage
    x:Class="SoloPathfinderPCL.UWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:forms="using:Xamarin.Forms.Platform.UWP"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SoloPathfinderPCL.UWP"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

</forms:WindowsPage>

Here's my Stack Trace for Exception: Cannot create an instance of "WindowsPage".

at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.InstanceBuilderOperations.InstantiateType(Type type, Boolean supportInternal)
   at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.InstanceBuilders.FrameworkElementInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.InstanceBuilders.UserControlInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
   at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ViewNodeManager.CreateInstance(IInstanceBuilder builder, ViewNode viewNode)

Hope someone can point me and everyone else having this issue in the right direction. Thanks.

Database view model using WHERE to select events

$
0
0

Hi, I have a database and i have connected it to a view page in a list, i want to have a where statement that narrows down the events so only some are displayed. would you recommend doing it in the view model or the actual view

Here is the view model

    [ImplementPropertyChanged]
    public class Database_ViewModel
    {
        bool _isLabelEmptyVisible { get; set; }
        TodoItem _selectedItem { get; set; }
        bool _isTapped { get; set; }
        int _count { get; set; }

        int Count
        {
            get { return _count; }
            set
            {
                _count = value;
                IsListViewVisible = (_count != 0);
                IsLabelEmptyVisible = (_count == 0);
            }
        }


        public ObservableCollection<TodoItem> List { get; set; } = new ObservableCollection<TodoItem>();
        public bool IsLabelEmptyVisible { get; set; }
        public bool IsListViewVisible { get; set; }


        public Database_ViewModel()
        {

            List.Add(new TodoItem { Time = "1:2:3", Event = "509m" });
            List.Add(new TodoItem { Time = "1:2:3", Event = "5091m" });
            List.Add(new TodoItem { Time = "1:2:3", Event = "5029m" });
            List.Add(new TodoItem { Time = "1:2:3", Event = "50m Freestyle" });
            Count = List.Count;

        }

Change only parts of traditional app to forms ?

$
0
0
Is it possible to start changing parts of a traditional app to become a forms app ?

Maybe even page by page, and having releases / updates inbetween ?

Some parts of my app could really benefit from the forms framework, others not ...

Xamarin app not showing anything

$
0
0

Currently developing an Xamarin app on Visual Studio 2013 but when i add buttons and such to the main.axml and deploy it.
It doesn't show the button on the emulator when i run the app


App crashing on Windows Phone when deplyed in Release mode

$
0
0

Hi,

We have developed a Xamarin Forms app supporting Android, iOS and Windows Phone. The app is working on all three OS when deployed in Debug mode. It's also working on Android and iOS when deployed in Release mode. It crashes immediately after displaying Splash screen on Windows Phone 8.1/10 when deployed with Release mode but strangely all works fine when deployed using Debug mode.

Any idea from experts here?
Is there any way to get see the app log to diagnose the crash reason?

Thank you,
Deepak Sakpal

Chars get cut off on larger Android Phone emulators - how to fix?

$
0
0

PCL project. I have a picker control. I have attached two images, of two different Android emulator phones. The XXHDPI image shows correctly (5" KitKat XXHDPI Phone (Android 4.4 API 19)), in that the entire character N or S shows. The XHDPI, (5.7" Marshmallow XHDPI Phone (Android - API 23)), cuts off the top of the N. At first I thought that it had something to do with XHDPI VS XXHDPI, but then I tried it on a 5.5" Marshmallow (6.0.0) XXHDPI Phone (Android 6.0 - API 23), and again the N was cut off. So...it has something to do with a larger screen size?

Haven't tested yet on Apple, will I need to do something different there?

Editor Effect app keeps crashing

$
0
0

Hello,

I've created an effect to set the background and text colors in a XF editor control. But everytime I try to use it, the app just crash on startup, running XF stable 2.3.3.180.

The effect looks like this (iOS):
`public class EditorColorEffect : PlatformEffect
{

    protected override void OnAttached ()
    {

        ((UITextView)Control).BackgroundColor = UIColor.LightGray;
        ((UITextView)Control).TextColor = UIColor.DarkGray;
    }

    protected override void OnDetached ()
    {

    }
}`

UWP Exception: Could not load file or assembly 'System.Core, Version=4.0.0.0

$
0
0

Hey Everyone,

I am running Xamarin.Forms version 2.1.0.6529.

My Android and iOS projects work perfectly but I thought it was time to do some work on the UWP project. However when I run the app in a Windows Mobile 10 emulator I am getting the following exception and I have no idea what it means. This happens straight away on boot up.

Exception thrown: 'System.IO.FileLoadException' in mscorlib.ni.dll
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Anyone have any ideas what I might be doing wrong?

Click listener on disabled drop down field

$
0
0

Can I register an event listener on disabled form field elements like a drop down to catch click events?

Here is the use case: Imagine a contact management app where a contact can have a spouse which is also a contact. In the form I can use a drop down field to select the spouse. In read only mode (fields are disabled) I want to allow the user to click on the spouse field and navigate to the details page of the spouse.

Viewing all 91519 articles
Browse latest View live


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