Show / Hide Table of Contents

Interface IItemPicker

Provides methods for showing an item picker dialog

Namespace: Sartorius.SAF.Presentation.Controls
Assembly: Sartorius.SAF.Presentation.Controls.dll
Syntax
public interface IItemPicker
Remarks

If you need an item picker as a control use the ItemPicker custom control.

Examples

The following example shows the item picker as dialog and shows the properties 'Header' and 'Description' of the items picked:

        var itemPicker = this.serviceFactory.GetInstance<IItemPicker>();
        var dialogArgs = new ItemPickerDialogArgs<Item>();
        dialogArgs.AvailableItems = Items;
        dialogArgs.SelectedItems = SelectedItems;

        dialogArgs.AddColumnDescriptor(it => it.Header);
        dialogArgs.AddColumnDescriptor(it => it.Description);

        // allow the user to order the result
        dialogArgs.IsSelectionOrdered = true;

        dialogArgs.Width = 800;
        dialogArgs.Height = 500;

        dialogArgs.Parent = Application.Current.MainWindow;

        dialogArgs.DialogTitle = "Pick Items";

        if (itemPicker.ShowDialog(dialogArgs) == MessageBoxResult.OK)
        {
            var selected = dialogArgs.SelectedItems.Cast<Item>().ToList();
            // do anything with the selected items
            // the selected items will have the order as intended by the user
        }

The following example shows the item picker and uses the Closed event to get the result:

        private void ShowItemPicker()
    {
        var itemPicker = this.serviceFactory.GetInstance<IItemPicker>();
        var dialogArgs = new ItemPickerDialogArgs<Item>();
        dialogArgs.AvailableItems = Items;
        dialogArgs.SelectedItems = SelectedItems;

        dialogArgs.AddColumnDescriptor(it => it.Header);
        dialogArgs.AddColumnDescriptor(it => it.Description);

        dialogArgs.Width = 800;
        dialogArgs.Height = 500;

        dialogArgs.Parent = Application.Current.MainWindow;

        dialogArgs.DialogTitle = "Pick Items";

        itemPicker.Closed += OnItemPickerClosed;
        itemPicker.Show(dialogArgs);
    }

    private void OnItemPickerClosed(Object sender, ItemPickerClosedEventArgs e)
    {
        if (e.Result == MessageBoxResult.OK)
        {
            var selected = e.SelectedItems;
        }
    }

The items picked in the above examples look like this:

        public class Item
    {
        public String Description { get; set; }
        public String Header { get; set; }

        public String SomeAdditionalText { get; set; }
    }

The following example shows an dialog and binds the Order and IsSelected members directly. When using binding the dialog only shows an OK button as the selection is directly bound to the IsSelectedMemberPath of the picked objects.

        var itemPicker = this.serviceFactory.GetInstance<IItemPicker>();
        var dialogArgs = new ItemPickerDialogArgs<Item>();
        // only non frozen columns can be shown/hidden by the user
        dialogArgs.AvailableItems = Columns.Where(it => !it.IsFrozen);

        dialogArgs.IsSelectionOrdered = true;

        // selected columns are visible -> bind IsSelected to Visibility
        dialogArgs.IsSelectedMemberPath = "Visibility";
        dialogArgs.IsSelectedMemberConverter = new VisibilityToBooleanConverter();

        // order of columns is defined by DisplayIndex
        dialogArgs.OrderMemberPath = "DisplayIndex";
        dialogArgs.OrderMemberConverter = new CalculateDoubleConverter {Operation = CalcOperation.Addition};
        // display index must be corrected by count of frozen columns as those are not selectable in the item picker.
        dialogArgs.OrderMemberConverterParameter = -Columns.Count(it => it.IsFrozen);

        dialogArgs.AddColumnDescriptor(it => it.Header);

        dialogArgs.Width = 800;
        dialogArgs.Height = 500;

        dialogArgs.Parent = Application.Current.MainWindow;

        dialogArgs.DialogTitle = "Pick Columns";

        dialogArgs.SelectionEmptyTitle = "No Columns selected";
        dialogArgs.SelectionEmptyMessage =
            "Select items in list “available” and click on function “select” in header of content box “available” or double-click on item in list “available”.";

        // show dialog, no check of result needed because of direct bindings
        itemPicker.ShowDialog(dialogArgs);

Methods

View Source

Show(ItemPickerDialogArgs)

Shows the dialog.

Declaration
void Show(ItemPickerDialogArgs args)
Parameters
Type Name Description
ItemPickerDialogArgs args

The arguments to configure the dialog.

Remarks

Use the Closed event to get the result.

View Source

ShowDialog(ItemPickerDialogArgs)

Shows the dialog modally.

Declaration
MessageBoxResult ShowDialog(ItemPickerDialogArgs args)
Parameters
Type Name Description
ItemPickerDialogArgs args

The arguments.

Returns
Type Description
System.Windows.MessageBoxResult

System.Windows.MessageBoxResult.OK if the user acknowledged his selection, System.Windows.MessageBoxResult.Cancel otherwise.

Remarks

args will contain the current selection of the user.

Events

View Source

Closed

Occurs when the item picker dialog is closed.

Declaration
event EventHandler<ItemPickerClosedEventArgs> Closed
Event Type
Type Description
System.EventHandler<ItemPickerClosedEventArgs>

Extension Methods

CollectionExtensions.AddRange<T, TCollection>(TCollection, IEnumerable<T>)
SerializableObjectCloneExtension.Clone<T>(T)

See Also

ItemPicker
ItemPickerDialogArgs
ItemPickerDialogArgs<T>
  • View Source
Back to top Generated by DocFX