Skip to content

SelectionView

Enis Necipoglu edited this page Jul 17, 2018 · 1 revision

SelectionView

SelectionView is a dynamic control. It needs a ItemsSource to generate views. It can handle single selections nad multi selections. You can bind SelectedItem for single selection type, and bind SelectecItems for multi selections.


SelectionType

Default value is Button.

Button

It's simple. Generates buttons for each object in your collection and able to select single of them. You can get selected object with binding **SelectedItem ** property.

RadioButton

Same with Button. User able to select one of selection. You can get selected one with SelectedItem.

CheckBox

Generates CheckBox for each object in ItemsSource and able to select multiple selections. You can get selected objects with binding SelectedIems.








ColumnNumber

Default value is 2.
That provides to decide inputs will be displayed in how many columns.







IsDisabledPropertyName

That is a propertyname. This property in your class must be a boolean, and decides that property is disabled or not.

For example you have an class like that:

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool OutOfStock { get; set; }
        public override string ToString() => Name;
    }

Just generate that list in a property:

    public IList<Product> Products { get; set; } = new[]
           {
                new Product { Id = 1, Name ="Blue T-Shirt", OutOfStock = false },
                new Product { Id = 2, Name ="Red Jacket", OutOfStock = false },
                new Product { Id = 3, Name ="Black Pants", OutOfStock = true },
                new Product { Id = 4, Name ="Yellow T-Shirt", OutOfStock = false },
            };

Then bind it like, set IsDisabledPropertyName as "OutOfStock", and when that property is true, it'll be disabled control. It can't be choosed.

      <input:SelectionView ColumnNumber="1" SelectionType="RadioButton" ItemsSource="{Binding Products}" IsDisabledPropertyName="OutOfStock" />

And the result:







DisabledSource

It's a source to disable controls. It must keep items from ItemsSource, and disables them.

For example you have an class like that:

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public bool OutOfStock { get; set; }
        public override string ToString() => Name;
    }

Just generate that list in a property:

    public IList<Product> Products { get; set; } = new[]
           {
                new Product { Id = 1, Name ="Blue T-Shirt", OutOfStock = false },
                new Product { Id = 2, Name ="Red Jacket", OutOfStock = false },
                new Product { Id = 3, Name ="Black Pants", OutOfStock = true },
                new Product { Id = 4, Name ="Yellow T-Shirt", OutOfStock = false },
            };
        
    public IList<Product> DisabledProducts { get; set; }= new ObservableCollection<Product>();

And add some data to DisabledProducts from Products:

     public MainViewModel() //Constructor
        {
            DisabledProducts.Add(Products[0]);
            DisabledProducts.Add(Products[2]);
        }

And just set DisabledSource from XAML:

         <input:SelectionView ColumnNumber="1" SelectionType="RadioButton" ItemsSource="{Binding Products}" DisabledSource="{Binding DisabledProducts}" />

And the result: