0

I wonder if it's possible to load ~70 buttons into WrapPanel better way that I'm using now.

At this momment it works like:

I have table in DB, columns: productID, productName (which represent 70 buttons to load, so there is always 70 rows).

Now in loop, using SqlDataReader I'm reading:

product.price (from table Product), barcode (from table Barcode) where Product.productID = myTableWithButtons.productID

If exist then:

using class to create button

returnButton(int productID, string picturePath, decimal price)

I'm returning button created from WrapPanel, 2 textblocks and (if exist) picture inside. If not exist - insert empty button without any text etc, and set it invisible.

Now tests: in core2 pc with 4 gb ram - tooks 0,91 sec to load in D525 processor, 2gb ram - tooks 4-5 sec to load.

Is there any way to load and insert buttons into WrapPanel ? Maybe some List<buttons> would be faster?

Every button have style in Resources file - gradient brush, WrapPanel with textBlocks as content etc.

Thanks for any reply! Regards

Darth Hunterix
  • 1,484
  • 5
  • 27
  • 31
user13657
  • 745
  • 3
  • 17
  • 36
  • 4
    use `ItemsControl`, change `ItemsControl.ItemsPanel` to `WrapPanel`, fill `DataTable` with your SQL and bind it to `ItemsControl.ItemsSource`, add template and WPF will create all buttons for you – dkozl Jul 02 '13 at 14:49
  • @dkozl beat me to it. That is exactly the way to do it. – Dave Williams Jul 02 '13 at 14:52
  • Fast and easy explain answer. thanks, ill check that :) – user13657 Jul 02 '13 at 14:56
  • By the way - I need to do something just like You said but with static Listview. In that way i need to wrte all ItemTemplate in codebehind. Can you help with any example? – user13657 Jul 02 '13 at 15:08
  • @user13657 why create control in code behind and what do you mean by static? why not in XAML? what do you want to achieve? – dkozl Jul 02 '13 at 20:13

0 Answers0