Disable ability to deselect an item - c#

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.

Related

UWP: Raise Key Down programmatically

I want to manage the listview while the text field is in focus. I mean the following case: I'm writing some text into the text box, but I am able to manage the list view selection in the same time by some keys(Up, Down).
I tried to change the SelectedIndex property, but I lose the automatic scrolling of the list view in this case.
I think it could be solved by raising key down event with a special key (Up, Down) for the listview - is there any way to do it?
you just need to use ScrollIntoView() method of ListView whenever you set the SelectedIndex of your ListView just follow it up with ScrollIntoView. you do it in 2 ways.
subscribe to SelectionChanged event and scroll the new selected item into view.
instead of setting SelectedIndex you can set SelectedItem and then scroll that item into view.
After setting the SelectedIndex, just get the item of that index and then scroll that item into view.

Selected ListViewItem is not highlighted on TabPage, after selected TabPage changed forth and back

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

WPF: Click partially visible row in listbox will scroll up instead of activating controls in the item

I have checkbox as item in a list box.
If you click a partially visible row in the listbox it will scroll up the list view to make the item fully visible, but not check the checkbox.
Is there any way to work around this?

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.

Categories

Resources