Selection bug for listbox where the list items are value types / structs and contain duplicates?

前端 未结 4 1945
耶瑟儿~
耶瑟儿~ 2020-12-19 16:04

I turned an Horizontal ItemsControl to a Listbox so that I am able to select individual items but found that the selection was broken. Took some time to distill out the prob

4条回答
  •  囚心锁ツ
    2020-12-19 16:48

    Garyx

    Something a bit simpler maybe ?

    public class StructListItem where T : struct
    {
        public T Item { get; private set; }
        public readonly Guid Id = Guid.NewGuid();
        public StructListItem(T item)
        {
            Item = item;
        }
    
        public static IEnumerable> 
            GetStructList(IEnumerable originalList) where U : struct
        {
            return originalList.Select(i => new StructListItem(i));
        }
    }
    

提交回复
热议问题