Prevent Multi-select in WPF Tab Control? - c#

It appears that in a WPF TabControl the user can select multiple items, either via Ctrl-Click or Shift-Click.
Is there a property that controls this? Or do I have to handle the click/select event and explicitly unselect other items?

Thanks to Moore's comment, I was able to solve this.
Each TabItem in the TabControl.Items collection needs a control to display the content. My program is using a ListView:
tabItem.Content = new System.Windows.Controls.ListView();
When creating each ListView, set the SelectionMode property to Single.
(Why that isn't happening, if Single is the default, is a mystery...)

Related

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.

wpf: how to edit selected item with possible cancellation?

I basically want to create something like this:
So, a user can add/remove items from the list and edit them in the red panel below the list. When the item is selected, the changes can be made in the panel.
Then, the changes can be either saved or canceled with one of the buttons below. User cannot select another item in the list without explicitly cancelling the changes.
How to do this? I only see the option of making the red panel a separate control and changing its DataContext manually on ListView.SelectedItem changes. The red panel's DataContext is a special wrapper on a ListView's item which has 'save' and 'cancel' options. ListView is set to IsEnabled = False so that its SelectedItem doesn't change when editing is in progress.
How would you do this?
The question is quite close from, for example, this one :
How do I stop binding properties from updating?
Anyway the WPF Object that will handle this is the BindingGroup :
http://msdn.microsoft.com/en-us/library/system.windows.data.bindinggroup.aspx
the most easy apporach is to use a dialog for edit a selecteditem. thats what i do in my project. i use this dialogservice and handle the result.
if you want to handle all in one view you could set a property SelectionEnabled=false when the SelecteItem is set. and then SelectionEnabled=true when the save or cancel command is invoked.
the datacontext for your edit panel is simply your SelectedItem.
You can try to use bindings with UpdateSourceTrigger=Explicit. The blog post Edit With Explicit UpdateSourceTrigger will give you more information about how this can be implemented.

Scrolling on List of User Controls with Listboxes inside in WP7

I have a list of User Controls in a screen in my WP7 app. Each User control has a header text block, a listbox and a button. And the listbox in the usercontrol will have it's height bound so as to show the complete height. Now when I try to scroll the list of UserControls, the manipulation events are being consumed by the ListBox inside.
One solution I can come up with is adding all the controls in a single ListBox and removing the UserControl. This might be weird. But that is my only option as of now. And also this is letting the ListBox item's height being recalculated. which gives a jumpy effect.
Is there better solution? Maybe we can disable the manipulation events on the listbox and allowing only tap event on the ListBox items?
First of all you need to disable inner list scrolling. Set ScrollViewer.VerticalScrollBarVisibility="Disabled" in xaml.
To disable manipulations on inner list, you should use ItemsControl instead of ListBox. Recent question about this: ListBox inside ListBox and selectedItem / Events

Silverlight: How to databind on a condition

I have an ItemsControl object and am setting the DataTemplate to hold a Grid with a couple controls in it. The controls are databoud to a collection of some object MyObj, specifically a TextBlock and a ComboBox. MyObj has its own collection inside of it for a property. If that property has only 1 object in its collection, only the TextBlock is visible. But if there is more than 1 object in the collection, the TextBlock is visible and the ComboBox becomes visible once the TextBlock is clicked on.
I have the ComboBox filled up with what it needs, I just can't figure out how to specify which ComboBox needs to become visible when the TextBlock is Clicked on.
I guess my question is, how would I even go about doing this? Or, is there a better way to think about this problem?
I'm new to databinding in Silverlight and running into a bunch of issues on my own. Any help is always appreciated. Thank in advance.
One thing that you could do is add an extra property to the data item that you binding to, something like 'IsSelectionAvailable'. Make the visibility of your combobox bound to this property (via a boolean to Visibility enum Value Converter). Finally, add a click event handler for the text box that sets the IsSelectionAvailable property to true for the object it is bound to.
Hope that helps.

WPF: Weird data-binding issue when using same data source on two controls

So i have a combo box on the main window of my WPF app. I bind a List accessed through a singleton to the ItemSource of the combo box. All is fine. In a child window that the user can open, i have a ListBox bound to the same List in the singleton.
The Problem: when i change the selection of the list box in the child window, i can see the selection change for the combo box on the main window at the same time.
What is causing these two very separate controls to behave like there is some kind of synchronization between them? Is it an issue with binding both controls to the same data object?
If both of your controls have "IsSynchronizedWithCurrentItem" enabled, you could see this issue.
You can find out more about this property here.
You can bind both controls to the same object without having them synchronized, just mark the "IsSynchronizedWithCurrentItem" property as false, and you should be good to go.

Categories

Resources