i have searched for days but not found any solution for the following Problem:
My parent is an TabControl.
In one tab i have an viewmodel with an listbox or listview with a lot of items.
when i select some item at the end of the list and then select an other tab an back to the list the item is select but i can not see it, because its outside the visible area.
What ca i do to fix the visible area ? So when i came back to my list the visible area of the listbox is the same as i leave.
sorry for the bad english :)
The visual tree (XAML) for a tab item is cleared when the selected tab changes, this is by design, this means things like the selected item in a ListBox\ListView are not remember by the View.
You have a couple of options:
Implement a tab control which remembers the visual state\tree for each tab - there are a lot of blog posts about how to do this,
or
You can remember the selected item in the ViewModel and when this is rebound when you go back to the tab it should scroll the selected item back into view. To do this you will have to bind the SelectedItem\SelectedItems properties depending on the selection mode you have chosen for the control.
Related
I am currently facing a strange behavior of the C#.Net ListView when used on a TabControl's TabPage.
Background:
I have said TabControl with three TabPages, the ListView is on the first one.
Scenario:
I select one Item in the ListView and its "Selected" property is set to "true"
I change to another TabPage
I change back to the first TabPage with the ListView containing the selected Item
Result:
The former selected Item in the ListView is not highlighted any longer. Iterating over all Items shows that its "Selected" property is still set to "true".
As soon as I click into the ListView control, I can see the selected Item being highlighted for a short moment, before loosing its highlighting again due to me having clicked somwhere else and therefore deselecting it.
But neither one of Refresh, Invalidate, RedrawItems, Focus or Select on the ListView leads to the selected Item being highlighted again.
Has anyone of you experienced the same issue and found a proper way to solve this?
My current solution is to clear the List of SelectedItems on the ListView as soon as the corresponding TabPage is re-focused, hence deselecting every Item and forcing the user to re-select what he wants to be selected.
But since I also noticed that ListBoxes can savely store their selection and display it properly, I would wish for the same feature on the ListView.
Thanks,
Thomas
I have a ListPicker (from Telerik's Rad Controls suite) in PopUp Mode (with around 200 elements) with its visibility set to Collapsed. I want to open when it when I press a button, instead of when I press the control itself.
Basically I'm asking if there's any way of programatically opening a UI element in Windows Phone (something like Control.Open() in the code behind).
The context for my question is the following:
as you know, the selected item of a list picker is displayed in the page containing the control.
users can click on this item to activate the control.
I want to display only one of the properties in the page containing the control (for example MyObject.Name instead of the entire MyObject), but I can't do this because the SelectedItem and ItemsSource need to be of the same type.
I'm thinking of styling a button to look identical to the ListPicker's selected item.
I need to open the ListPicker programatically when I click on the button, I'll bind the button's text to MyObject.Name
Alternatively, I could just do a data template for the way the list picker is displayed, but I'm not convinced it's possible.
Found the answer. It seems Telerik's List Picker allows you to set both an ItemTemplate for displaying items in the actual page, and a PopupItemTemplate for displaying items when the list is expanded. Both are Data Templates, so you can use Binding for values.
I have a Grid bound to an ObservableCollection. I want to have an extra item in the grid such that it displays as just another tile but is actually, e.g., a button. Microsoft's Finance app demonstrates the effect I want perfectly (screenshot below). The goal is to have a final tile that is not itself a member of the collection, but sits in the grid like any other item.
The top answer to a similar question mentions the CompositeCollection, but CompositeCollection does not seem to be available for Win8 apps.
You could always add and extra item at the end of the ObservableCollection, you're binding to.
You could handle this exception in the view model: add it during loading, properly handle adding and removing the rest of the items if you support that in your app. (That's the approach we took in one of our projects.)
Or you could derive your own class from ObservableCollection to handle all that and reuse it.
To have the extra item display differently from the others, you can use a DataTemplateSelector and select the right template based on the type name or some other property that differentiates the extra item from the rest.
Here's sample project which shows standard items template (GridView, with ListView for snapped view) that adds a "+" content item to the ItemsSource, which is used for the "Add New Item" action in the app.
"Add New Item" item in GridView / ListView
I have a Popup control in my application. In this popup I use a ListPicker object to choose
the proper item. If the list of items if quite small, everything works fine, but, however, if the list items number is big, the list of items is shown at a new page somewhere at the background. That's the native behavior for ExpansionMode.FullScreenOnly of ListPicker, but I can't use it that way.
Is there a way to make a list of items scrollable to save the ListPicker behaviour of ExpansionAllowed style?
If not, is there a similar control in Windows Phone, that allows to create a drop-down menu in that style?
Right, let me show the difference:
1) That's how it should work, the number of elements is quite low, there are only four of them. When I click at the item (item has a name 2012-12-17) a list of items is shown in drop-down menu.
2) That's the problem one. The number of items is high, there are more than ten. When I click at the current item, the drop-down menu isn't shown in this popup, instead it's shown at the new page (could be seen in background). But that breaks all my logic, I can't even choose another element(can't click on it, because you can't click on page when popup is opened).
Can anyone propose a solution?
The ListPicker control seems to be useless, as I couldn't find out how to solve this problem.
The solution will be to use different control, for example ListBox, which is scrollable by default. (will be similar to Scrolling ContextMenu items question solution) That will be differ from the UI-style I wanted, but it will work.
Is there a way to disable the ability to delect an item in ListView?
I have a SplitPage and when I deselect the selected item in ListView on the left the content on the right disappears because of lost databindings. I do not want that. I tried setting the ListView selectedItem back to the last one selected but the the back button in snap mode does not work
You can set the selection mode to none and set your ItemTemplate to a restyled ToggleButton. Then you can bind the Enabled property of each button to the item view model and control the enabledness of each of them buttons separately.