I have a with <CollectionView.ItemTemplate> with and I would like to display the current row number of each one. Is it possible and if so how?
Best way to do it is to just add an Index property to the Item your binding the item templates to and fill that index from the ViewModel. Templates will be reused, so the template used at index 0 can later appear at index 10 etc.
Related
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Navigate between panorama items wp7
I have a listview in the default PanoramaItem with other PanoramaItems Like category, favorite, settings etc. All these PanoramaItems are listed in the listview and on change in selection of listview item it should take to the corresponding PanoramaItem. But i tried to change using Panorama.selectedindex but it is readonly property. The other approach was to change defaultItem on OnNavigationTo event but since my listview is inside same Panorama hence this approach won't work. Is there some direct aproach to this?
Just set the default item to which item u want to load for the user's view..
panSOS.DefaultItem = panSOS.Items[1];
In your SelectionChanged event handler of the ListView, you should be able to set the DefaultItem of the Panorama to the particular item you want to view.
I have a list item with a datatemplate that has a several components all inside a stackpanel. Now i want to split size of the rows of the list evenly among the number of items in the list (depending on the number of rows) so if there are only 2 items in the list, the height of each of 2 the listitems will be (800/2), if 3 (800/3) e.t.c. (there's are limit at which the row size will remain constant)
My problem is how to do i bind this calculated height to the container (stackpanel) of the listitem? since i have set the listitems itemsource property and the 'container' is inside the list?
The way I would tackle this would be to create a ValueConverter that looks at the number of items in your List<T> and does the math to calculate how tall the individual StackPanel elements should be. It would then return this value as an int.
To put the pieces together, in your XAML you would bind your StackPanel.Height property to the Count property on your List<T>, specifying your ValueConverter as the property's converter.
The DataContext might get a little tricky when you try to access the Count property, since the StackPanel will have its DataContext set to the individual list item. But you can probably work around that by adding a Count property to each item in your list.
Here's a good post](http://www.jeff.wilcox.name/2008/07/visibility-type-converter/) about ValueConverter. It covers converting a bool to a Visibility property, but the concepts are the same.
is it possible to hide and show a pivot element?
e.g. i want a option in my app in which i can show or hide one special pivot item which is not usefull for every user.
It appears that it's not possible to hide an entry in the items collection.
The only option available is to remove and add the item from the pivots Items collection.
Depending on the application and the design of the pivot it may be appropriate to leave the item always there but give it the header "advanced".
You can remove the pivot item from the parent pivot control
parentPivotControl.Items.Remove(pivotItemToBeRemoved);
How can I place listbox item separated from each other or leaving some space in between.
I believe if you have a datatemplate, you can just add the following code to the listbox itself: Margin="10" (or any number you like) and that will set a space between each item.
Are you using a template for the listbox items? Are you using databinding and the DataContext or ItemSource properties? I'm sure you can add margins to the items you add to the template to create the space you desire. Check out Nerd Dinner Example for use of a template.
There are two ways. May be both are stupid...
I have to display some collections of items.
First one.
I use DataTemplate for ListBoxItem.
Just set itemSource = myCollection;
That's all. Simple scheme.
Second one.
Each item in my collection has property view. It's a UserControl. That define how item renders.
Create DataTemplate with ContentPresenter only.
Binding Content property to a view.
Just set itemSource = myCollection;
That's all. More complex. But works too.
Has second one right to live? My doubt is that I have to create instance of UserControl for every item in my collection?
Is not it too expensive for collection with over than 500 items?
Thanks.
I don't believe there is much difference, with the DataTemplate approach the framework will create an instance of the DataTemplate for each item in the collection. In the second approach an instance of the user control will be created for each item, there may be a few more controls but only a few per item.
One reason the second approach could be preferable is that you can have logic around which content is bound. This could mean different user controls for each item in the list. Caliburn Micro lets you use this approach very naturally.