Coder Social home page Coder Social logo

maxcabanillas / xamarinformsbindablepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from seiya1223/xamarinformsbindablepicker

0.0 2.0 0.0 108 KB

BindablePicker control, a replacement for the Xamarin Forms Picker

Home Page: https://oceanware.wordpress.com/2016/08/12/xamarin-forms-bindable-picker-v2/

License: MIT License

C# 100.00%

xamarinformsbindablepicker's Introduction

Xamarin Forms BindablePicker

After downloading or cloning, you MUST right-click the solution and select "Restore NuGet Packages."

After restoring, I always restart Visual Studio. I know you shouldn't have to do this, but I found it covers 95% of my headaches.

Introduction

This repro contains the updated Xamarin Forms BindablePicker control (8/12/2016 Release).

This control is a replacement for the Xamarin Forms Picker.

Bug Fixes

9-30-2016 - Corrected BindablePicker to handle the view model clearing the Items ObservableCollection

9-6-2016 - Corrected InternalSelectedValueChanged method to property check object equals. SelectedValuePath works with all data types now.

8/12/2016 - Corrected the ItemsSource implementation, that failed to reload new collections property when the selected item was immediately reset after refreshing the ItemsSource.

Demo Project

The XamarinFormsBiundablePicker project is a simple Xamarin Forms, UWP project that demonstrates usage scenarios for the BindablePicker.

The BindablePicker class is in the Controls folder, grap this file and add to your projects.

Features

new (8/12/2016) BindablePicker supports binding the ItemsSource to an ObservableCollection

Classfile

  • DisplayMemberPath used in conjunction with the SelectedValue property, determines which property will be displayed in the picker.
  • ItemsSource bindable, supports ObservableCollections and collections that implment INotifyCollectionChanged.
  • SelectedItem bindable, used when the ItemsSource is a collection of strings
  • SelectedValue bindable, used in conjunctin with DisplayMememberPath, and SelectedValuePath, is set to the value of the SelectedValuePath when an item is selected.
  • SelectedValuePath used in conjunction with the SelectedValue property, determines which property will be returned by the SelectedValue property when an item is seleced in the picker.

Usage

SelectedItem - Collection of strings, data bound to a string model property

<controls:BindablePicker
    ItemsSource="{Binding Path=VacationSpots}"
    SelectedItem="{Binding Path=Person.NextVacationSpot, Mode=TwoWay}" />

SelectedItem - Collection of strings, data bound to an enum model property, uses enum converter

<controls:BindablePicker
    ItemsSource="{Binding Path=Sexes}"
    SelectedItem="{Binding Path=Person.Sex, Mode=TwoWay, 
                    Converter={StaticResource SexEnumConverter}}" />

SelectedValue - Collection of Country objects, data bound to a string model property

<controls:BindablePicker
    ItemsSource="{Binding Path=Countries}"
    DisplayMemberPath="Name"
    SelectedValuePath="Abbreviation"
    SelectedValue="{Binding Path=Person.Country, Mode=TwoWay}" />

Example of adding a new item to the source collection, item is added to the BindablePicker Items.

Code from the PersonEditorViewModel.cs file

void AddOnItemToVacationSpotsExecute() {
    this.VacationSpots.Add("Hawaii");
}

Example of refreshing the ItemsSource and resetting the selected item.

In the below code, the SelectedItem on the BindablePicker is bound to the Person.NextVacationSpot property.

Code from the PersonEditorViewModel.cs file

void RefreshVacationSpotsExecute() {
    // simulates the vacations spots being refreshed from the data base.
    var list = this.VacationSpots.ToList();
    list.Add($"New Spot {DateTime.Now.ToLocalTime()}");
    this.VacationSpots = new ObservableCollection<String>(list);
    this.Person.NextVacationSpot = list.Last();
}

xamarinformsbindablepicker's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.