Accommodate custom item on winrt listview - c#

I'm developing windows metro app. In my application, I've one Listview with wrapgrid in itemspanel to display list of items on vertical rows with specific height. I want to display one item on top of the first column of list view, which shows result/stats of list items.
I would like to know if it is possible without adding custom item to datasource of listview?

ListView has a Header property in which you can Place content before the ListViews Items.

As commented, I've implemented following solution which is not elegant but worked for me.
Use Datasource converter to add dummy item in main list. So, my original list remains as is.
Use Template Selector to bind different template for first item.
Handle Selection and clicked event of dummy item.

Related

Update DataTemplate for a specific item on a listbox on Windows Phone 8 C#

I'm not being able to update a single item's DataTemplate on a list during runtime. In detail, here is what I'm trying to accomplish.
I have a Listbox where the items can have different states (Collapsed, expanded, disabled, etc), each with a different layout. I'm using a TemplateSelector to choose the correct DataTemplate according to a property on my class and that's working all great when I first create the list, the items are shown properly. However, when I change the property that sets the DataTemplate in runtime, the NotifyPropertyChanged is called and the information of the item is updated on the list, but not the DataTemplate. For example: I have a collapsed item with a label X that i want to expand. I click on the item and the label changes to Y but the DataTemplate doesn't update.
Any idea on how I can do this? Can't the DataTemplate be updated during runtime unless it is for the whole list?
I'll appreciate any help.
Make UserControl and use it inside your data template. Now, to change the state you can call methods on this UserControl and it will update. You can use animations via storyboard too.

Getting the Selected Item among items present in Grid

I am implementing a Media Player application using WPF. I want to display a List Screen where the user can select the video from a list.
I want to display the videos in a list horizontally(without scrollbars so not using ListView) where each item consists of a thumbnail, title and duration.
Now I also want to obtain which item was clicked on so as to play the correct video. I tried to display the items in a WrapPanel which sufficed for display but doesnt have a SelectedIndex property.
Will a Grid be helpful in this regard? If yes then how do I obtain which item was selected in the Grid?
Use a ListBox.
WPF UI elements keep their appearance separate from their functionality. If you want a list of items where you can select one, use a ListBox. If you want to customize how it looks, simply change its Template.
Grid, WrapPanel, StackPanel and the like are just Panel UI element which are used for Layout. They don't derive from Selector and thus don't have any item selection features.
Since you didn't post any relevant XAML in your question, I'll not post any relevant XAML in my answer.

Populating a panel with selected items from a grid in WPF

I have a DataGrid with a bunch of rows representing items in my system. I want that each time a user selects an item in the grid (the user is allowed to select multiple items) the item will be added to a StackPanel and have its own datatemplate using an Expander to display its data.
Can anyone help me do this in WPF?
Thanks!
John.
I wouldn't use a StackPanel, but an ItemsControl, and bind its ItemsSource to the DataGrid's SelectedItems. However, at the moment I'm not sure whether SelectedItems has change notification. If not, you might have to use a CollectionViewSource in between, and call CollectionViewSource.Refresh during the DataGrid.SelectionChanged event.

WP7 Panorama items binding and adding other custom panorama items c#

I am running into an issue where i am using a panorama control and binding it to a datasource. But i still do want other custom items on another panorama items where i need a textblock, a grid and so on. So if i am adding it in the backend it doesnt show up those panorama items. It just shows the datasource binded items. Why is that so? Both of them should work out.
Can anybody help me with a solution for this.
Thank You.
Since you're wanting to manually add PanoramaItems, I can think of two approaches:
Make sure your Panorama.ItemsSource is set to an ObservableCollection that is accessible in the code behind or viewmodel, and then add your new items to that ObservableCollection which should update the Panorama.
Don't databind the Panorama control's Items - just add items manually when you want them.
Either way, the Panorama's ItemTemplate gets evaluated when the items are added to the underlying collection, so using a DataTemplateSelector will allow your code to determine which DataTemplate to apply when the new item is added without affecting the templates for previous items.
/chris

Winform ListView databind

I have a Listview that uses databind. I set the DataSource property to a binding source. All works fine. The problem is that I need to have a column that is not databinded and contains only buttons that have the same handler for click event. To accomplish this I tried to add a subitem that is a button for each ListViewItem after InitializeComponent but doesn't work, nothing is displayed. Also I set the list view column type to Control.
If I add elements to ListView and isn't databinded that the buttons appear.
So it will be a great help for me to know if buttons could be displayed in column that is not databinded when the listview uses databinding for rest of columns.
Thanks!
The best thing to do here (assuming you mean ListBox), is to have a single button above or below the listbox, that uses the ListBox.SelectedItem property to investigate the selected item and do something with it.

Categories