dynamically adding images to a list box in WPF - c#

I have a WPF application that has a vertical listbox that I would like to programmaticly add images to. I want to be able to use a FileSystemWatcher to monitor the directory that the photos are in and when a new image is added or an image is deleted the list box will update the images in the application. Does anyone know how to accomplish this?

Very roughly, you bind the ItemsSource property of the ListBox to an ObservableCollection of images. Have your watcher process add images to the collection as they appear, and databinding should cause the ListBox to be updated as the backing collection changes.
Further: How to: Create and Bind to an ObservableCollection
That's the general concept. Can't get much more specific than that without knowing anything about your code. :) Good luck!

Related

load the entire ListView in background and get an UIControl inside each ListItem

I need to load a ListView entirely and get an UIControl inside each ListItem even if the item view is not displayed on the screen.
I tried the ChildViewAdded event, but it is raised only when the ListItem is displayed on the screen.
So, I need a way to prepare my UI ListView programmatically before displaying it.
Thanks in advance for your help.
Quick answer - if you need a real View for each item in your list then you don't want to use a virtualized control like a ListView.
Instead you can use repeated custom views inside a vertical LinearLayout inside a ScrollView.
If using mvvmcross, you may find a MVXBindableLinearLayout helpful to do this - it has an ItemsSource and a Template just like the MvxBindableListView.
I've no idea whether what you are trying to do makes sense, but the above should help you do it if you want to!
Don't try using a linear layout for lists with lots of items - you'll run out of resources.

How I can add edited images to ListView from a ViewModel?

I have an app with simple MVVM implementation with ListView on my View.
I need to add images to ListView, but not just images. I need to draw something on that images.
I have a model which consists of filepath, middle and theta properties. And I need somehow to bind edited images to ListView.
What is the proper way to accomplish that? How I can add edited images to ListView from a ViewModel?
Edit the images in C# code before adding them to a collection that is used in binding
Edit the DataTemplate and overlay each image with XAML Path geometry
Other options?
It's really not easy to answer because you don't state how you plan to edit the image...

WPF - Display db records into a list

I am quite new to WPF and XAML but my background is of ASP.NET and C# so I have a vague idea of how it works.
In .net, I can use the repeater, datalist, gridview, bind to them a DataTable and output from that DataTable. I am now wanting to do the same with WPF.
Basically, I want to display simple records from a database (preferably using a DataTable as I usually work with those). The list might be something like this with two columns
1) Grey TV
2) Red car
3) Blue motorbike
I have looked around but I can't get a definitive answer on what control to use. Some people say ItemsControl and some people say DataGrid. Can anyone help me here?
Thanks in advance.
A DataGrid is used for displaying Table-like data (Per record multiple columns). An ItemsControl is used to display data using your own ItemTemplate, in which you are unlimited in how to represent the items and in what directions or alignments.
Another good useable control for you might be a ListView, which works just as a ListBox except it doesn't have any selection logic. And you can choose between four different ways of displaying your items using the View property (http://msdn.microsoft.com/en-us/library/system.windows.forms.view.aspx).
In your case I would suggest using a ListView.
To bind any items to the control, you have to set the DataContext on the UserControl or the Control itself. And then bind the ItemsSource property to a local List or Collection using the Binding markup extension (http://msdn.microsoft.com/en-us/library/ms750413.aspx). To learn more about data-binding go here:
http://msdn.microsoft.com/en-us/library/ms752347.aspx

Share listbox across controls/pivot items on WP7

I was wondering if there was a way to share a listbox on the same page.
Basically, I have a listbox that is bound to a collectionviewsource. I also have 5-6 pivot controls that will use the same listbox, but will filter the collectionviewsource differently.
I was wondering if it was possible to say have a listbox as a resource and display it on all hte pivots then when the pivot changes, I can apply a different filter to the collectionviewsource.
Can anyone steer me the right way?
Thanks!
You could create an ItemTemplate for the Pivot which includes the listbox.
I find it easier to maintain this scenario by explicilty creating each pivotItem in XAML but having all teh listboxes share the same ItemTemplate though. I find it easier to see what's going on by just looking and it also makes it easier if you ever need to change the template of one of the listboxes. (I find this seems to happen quite often.)

Creating a ListBox of images?

How can I create a ListBox control on my Winforms application that has images in an orderly fashion, just like it holds text?
I'd like the images to appear like this:
Maybe I don't even need to use a ListBox. Maybe there's a better control out there for this purpose? Thanks!
You possibly want an owner-draw list box. There's an example on the MSDN page for the DrawItem event.
Load all your images into an imagelist, using a unique key for each image, such as a filename. Make sure you set the imagelist imagesize to the size of the images.
Set the listview LargeImageList property to the imagelist you loaded.
Assign the imagekey property of each listview item to the key that matches its image in the imagelist.
Set the listview view style to view.largeicon.
Profit.

Categories

Resources