示例#1
0
        /// <summary>
        /// Use a SelectItemsDialog to choose a single item from the specified collection
        /// </summary>
        /// <typeparam name="TItem">The type of the item to choose</typeparam>
        /// <param name="caption"></param>
        /// <param name="items"></param>
        /// <returns>The selected item if one is chosen and the dialog is not cancelled, else null</returns>
        public static TItem SelectItem <TItem>(string caption, ICollection <TItem> items)
            where TItem : class, INamed
        {
            var dialog = new SelectItemsDialog(caption, (ICollection)items);

            if (dialog.ShowDialog() == true)
            {
                return(dialog.SelectedItem as TItem);
            }
            return(null);
        }
示例#2
0
        /// <summary>
        /// Use a SelectItemsDialog to choose a subset of items from the specified collection
        /// </summary>
        /// <typeparam name="TCollection"></typeparam>
        /// <param name="caption"></param>
        /// <param name="sourceItems"></param>
        /// <returns></returns>
        public static TCollection SelectItems <TCollection>(string caption, TCollection sourceItems)
            where TCollection : class, IList, ICollection, new()
        {
            var dialog = new SelectItemsDialog(caption, sourceItems, SelectionMode.Multiple);

            if (dialog.ShowDialog() == true)
            {
                TCollection result = new TCollection();
                foreach (object item in dialog.SelectedItems)
                {
                    result.Add(item);
                }
                return(result);
            }
            return(null);
        }