Scrollable ListPicker items list - c#

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.

Related

Forcing listview to scroll down to a particular group. C#

I'm having a listview control on my windows form accomodating number of items under particular groups ,namely hardware, sanitary, tools, paint etc etc. Since the list of items can be too big to choose items from in reasonable time, so I have a menu strip above the listview control containing the names of the groups inside the listview control, what i want to do is to have a handler for a menu strip that scrolls down the listview to the particular group to save the time.
how can it be done, i did google, but couldn't come up with a good way of doing it.
There are two ways to do this. The first is to get the first item in the desired Group, then use the EnsureVisible method on it. This will do what it sounds like, make sure that item is visible. If it is off-screen, it will scroll that item to the bottom of the viewable items:
// ToDo: check that the groups HAS items
ListViewitem lvi = myLV.Groups["myGroup"].Items[0];
lvi.EnsureVisible();
Another way -- which is probably what you want -- would be to try to make that same ListViewItem the TopItem which may scroll more of the Group into the viewable area:
myLV.TopItem = lvi;

c# MVVM Listbox Remember Selected Item after TabChange

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.

Manually opening a ListPicker

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.

Custom wpf tab control with one permanent tab, all other tabs scrollable

I need to create a control which has a single permanent tab ("home"), and all of the other tabs are scrollable.
Right now I am trying to achieve this result by subclassing the TabControl, adding an extra button (which looks like a tab) to the overridden template, and setting the SelectedIndex to -1 whenever the button is clicked. When SelectedIndex is -1, a trigger causes the TabControl's ContentControl to be bound to a special "Home" tab's content. Basically, I am faking the behavior of a real tab and overriding the ability to deselect all tabs in doing so.
This seems to work, except for two problems:
Select example tab #3, then select home. THEN, try to select tab #3 again. Tab #3 doesn't respond.
Select tab #3, then select home. THEN, try to use the menu which happens to be in the same window. When I go to use the menu, #3 pops up as the selected tab again.
I've tried to listen to all kinds of events associated with the TabControl at this point, but none of them seem to give me something I can work with to get around these behaviors.
Is there something out there that will allow me to override the default SelectedIndex behavior? Should I be doing this another way? Ideally, I would like some way to take in a collection of tabs that allows me split up the tabs visually without losing the basic functionality of a TabControl.
The only way I can think of to accomplish this would be to use a custom ControlTemplate for the tab control. You can use StyleSnooper to get the current template. The that is part of that template would need to be replaced with a custom panel that you wrote. You base that on Panel. You would only need to override ArrangeOverride so that it arranged the Home tab in its place, and the others depending on the scroll position.
I was able to implement this by writing my own custom tab panel, as AresAvatar suggested. However, the panel needed to extend from the ConceptualPanel implementation from http://www.codeproject.com/KB/WPF/ConceptualChildren.aspx. The problem is that the panel needs to have IsItemsHost="true" in the TabControl template to preserve the tabs' selection behavior. Unfortunately, once a normal panel is an items host, it's Children can't be changed from inside it's own class code. So, I couldn't add the scroll buttons that I needed. I was able to get around that problem with the ConceptualPanel by adding everything (tabs + scroll buttons) via AddVisualChild.
There might be a better way to do this, but this worked for me.

.NET Is it possible to have a contextmenu on an item of a combobox?

In my application I have dropdown list with several items. I'd like to show a context menu when the user clicks the right mouse button on a dropdown item. Is this possible? And if it is possible, how?
It is possible but not easy. The ComboBox dropdown is a native ListBox that is created on-the-fly. To get the handle of that list box, you have to send the CB_GETCOMBOBOXINFO message in the DropDown event. Check my answer in this thread to find out how to do this.
The iceberg that is likely to sink that Titanic is that the dropdown automatically closes as soon as it loses focus. Which will happen as soon as you display the context menu. Nothing you can do about that.
Consider a different approach, you could use an actual ListBox that you make visible when the user clicks a glyph that looks like an arrow next a TextBox.
Not possible easily. No hover or right-click event messages are being sent when the combobox is expanded.
You can see this is the case when using Spy++.
I think the easiest would be to change to a listbox if your scenario allows you to do that.
As Wim said in his post, there's not a direct way to do this because the messages you want aren't fired.
As a comprise, you could try setting DropdownStyle=Simple; on the Combo and
shrink the scroll region to show a single line:
http://img34.imageshack.us/img34/1695/49557147.jpg
If you assign the Combo a context menu, it will open when the scroll region is right-clicked. You'd probably have to figure out what item was right-clicked. But as other have said, this doesn't sound like a standard Windows way or an intuitive use.
Or how about a modal dialog that you could bring up from the Combo's context menu? On the dialog, you could have a list that the user could select from and a Delete button to delete the selected item(s).
Since MenuItem doesn't have a ContextMenu property it isn't as easy as it is with many other controls. You'll probably need to capture the right-click event and then position and show the context menu manually.
Two caveats though:
The combobox list will close when the
list loses focus, so it may close
when the context menu is shown
leaving the user unclear as to what
they clicked on (not 100% sure on
this, since I haven't written the
code to test.)
More importantly though I would argue
that this is a poor UI choice, I
can't think of any real world
applications I've used that have
context menus on menu items, so it
wouldn't be very discoverable for the
end user. Plus context menus should
be just for quick access, they
shouldn't be the only way to access
functionality. Are you going to be
able to expose these functions
through other means as well as the right-click menu?
You could do it manually, by capturing the event on the form, but consider making a nested menu instead. If your combobox items have menus of their own, combobox probably isn't the right choice.
For those asking "Why?" or saying they've never seen a combobox with a contextmenu; Look at any web browser's favorites dropdown. You can right click and delete, edit, or go to the entry in current tab, new tab, or new window.
I also could not get an actual contextmenustrip to show, so I made a menu with a small borderless form and call with:
Private Sub FavoritesBar_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles FavoritesBar.SelectedIndexChanged
FavIndex = FavoritesBar.SelectedIndex 'FavIndex is declared as a public string.
Dim Loc As Point = New Point(MousePosition)
FavMenu.Location = Loc
FavMenu.ShowDialog()
End Sub
With a homemade contextmenu, be sure to add "me.close" at the end of each sub as well as the me.mouseleave event.

Categories

Resources