Telerik WPF - TreeMap Select item programatically - wpf

Is it possible to select an item programatically? After I bind the TreeMap control I would like to select a default item.

Sure. Set the IsSelectionEnabled property to true and then set or bind the SelectedItem or SelectedValue property to an item in the ItemsSource like you would do with any other ItemsControl.

Related

Same ItemsSource in multiple ComboBox elements, SelectedIndex synced for all ComboBox elements, want separate

I have multiple ComboBox elements. Each ComboBox's ItemsSource is bound to the same property. That property is a ListCollectionView whose underlying list is an ObservableCollection. Each ComboBox's SelectedIndex is bound to a different property. My problem is that when the user changes one ComboBox all the others are changed to the same item.
How can I make the SelectedIndex properties independent? Do I need to use something other than ListCollectionView or ObservableCollection? Would binding to something other than SelectedIndex help?
After some poking around I found that the ComboBox property IsSynchronizedWithCurrentItem fixed my problem. When set to false my ComboBoxes became independent.

using WPF Caliburn, How do I change datagrid binding based on the combobox selection?

about to add the following features
If select this combobox, I want to change the itemssource of the datagrid.
Are there any examples related to this?
You can do the following:
Create a WPF project.
Create a view (xaml) with the combobox and datagrid inside it.
Create a view model for this newly created view and declare public properties (collection/list) for the ItemsSource of the combobox and the grid. Also have a property for the selected item of the combobox.
Set this view model as the data context of your view.
In the setter of the combobox's selected item - change the property which is bound to the datagrid's ItemsSource to the collection that you by calling a method or however you wish.
I did this:
Add the namespace for caliburn in xaml
xmlns:cal="http://www.caliburnproject.org"
Here is the combobox:
<ComboBox ItemsSource="{Binding ComboBoxItemSource}" SelectedItem="{Binding SelectedItem}" cal:Message.Attach="[Event SelectionChanged] = [ComboBoxSelectionChanged()]" />
and the viewmodel should be having this method:
public void ComboBoxSelectionChanged()
{
// here based on the SelectedItem you can change the ItemSource for the dataGrid.
}
Whenever you are changing the selectedItem of Combobox the method will get hit and based on the logic that you need you can assign the ItemSource for the dataGrid.
Hope this helps :)

How to get current item index of ItemsControls in viewmodel?

How to get current item index of ItemsControls in viewmodel?
We want to delete the selected textbox item using ctrl+D in the itemscontrol from the viewmodel
As #metacircle has mentioned, you should use a ListBox, which has this functionality built in, instead of your ItemsControl. Using a ListBox, you have a number of options for accessing the selected item:
SelectedIndex Property
SelectedItem Property
SelectedValue Property
You can find code examples on these pages on MSDN and further examples in the ListBox Class page.
ItemsControl does not have the concept of "current item" nor "current index".
You're looking for a Selector-derived control, such as ListBox

Programmatically highlight combobox item

Is there any way to highlight comboboxitem programmatically?
Property IsHighlighted has no setter((. Changing style is not enought.
If you goal is to select rather than highlight (the IsHighlighted property is used to indicate a selected item), you can just set the IsSelected property or the SelectedItem or SelectedValue of the parent ComboBox.

Selecting TabItem from code-behind when tabs use a DataTemplate

I've got a TabControl in my WPF application. The TabControl's ItemsSource is bound to an ObservableCollction of view objects. It uses a DataTemplate to populate the visual tree for the tabs from the Items in the collection.
I need to be select the current tabs in the conde-behind in response to actions the user takes on another screen in the application. When I iterate over the items in the TabControl's Items collection, I get the instances of my view models.
How do I access the actual TabItems and iterate over them, then select the one I want?
Tony
If you're using a MVVM approach you should bind your TabControl's SelectedItem property to the same object that holds your ObservableCollection of TabItems (the ViewModel). When you need to change the current tab set the SelectedItem property to the correct TabItem in the ObservableCollection.

Resources