What is the simplest way to get the selected text of a combo box containing only text entries?

In your xml add SelectedValuePath=”Content” <ComboBox Name=”cboPickOne” SelectedValuePath=”Content” > <ComboBoxItem>This</ComboBoxItem> <ComboBoxItem>should be</ComboBoxItem> <ComboBoxItem>easier!</ComboBoxItem> </ComboBox> This way when you use .SelectedValue.ToString() in the C# code it will just get the string value without all the extra junk: stringValue = cboPickOne.SelectedValue.ToString()

WPF binding to Listbox selectedItem

First off, you need to implement INotifyPropertyChanged interface in your view model and raise the PropertyChanged event in the setter of the Rule property. Otherwise no control that binds to the SelectedRule property will “know” when it has been changed. Then, your XAML <TextBlock Text=”{Binding Path=SelectedRule.Name}” /> is perfectly valid if this TextBlock is outside … Read more

How do you programmatically set focus to the SelectedItem in a WPF ListBox that already has focus?

It’s a couple lines of code. If you didn’t want it in code-behind, I sure it could be packaged in a attached behaviour. private void Button_Click(object sender, RoutedEventArgs e) { MainListBox.SelectedItem = MainListBox.Items[3]; MainListBox.UpdateLayout(); // Pre-generates item containers var listBoxItem = (ListBoxItem) MainListBox .ItemContainerGenerator .ContainerFromItem(MainListBox.SelectedItem); listBoxItem.Focus(); }

highlighting only the selected item in the listview in Android

ListViews by default don’t have a choiceMode set (it’s set to none), so the current selection is not indicated visually. To change this, you just need to set the choiceMode attribute of your ListView to singleChoice. If you’d like custom background for the selected items in your list, you should also set the listSelector attribute. … Read more

Getting selected value of a combobox

Try this: private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmb = (ComboBox)sender; int selectedIndex = cmb.SelectedIndex; int selectedValue = (int)cmb.SelectedValue; ComboboxItem selectedCar = (ComboboxItem)cmb.SelectedItem; MessageBox.Show(String.Format(“Index: [{0}] CarName={1}; Value={2}”, selectedIndex, selectedCar.Text, selecteVal)); }

Selecting a Textbox Item in a Listbox does not change the selected item of the listbox

We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such: <ListView.ItemContainerStyle> <Style TargetType=”ListViewItem”> <EventSetter Event=”PreviewGotKeyboardFocus” Handler=”SelectCurrentItem”/> </Style> </ListView.ItemContainerStyle> And then we select the row in code behind: protected void SelectCurrentItem(object sender, KeyboardFocusChangedEventArgs e) { ListViewItem item = (ListViewItem) sender; item.IsSelected = true; }

WPF TreeView: How to style selected items with rounded corners like in Explorer

Adding to @Sheridan’s answer This isn’t a 100% accurate but should get you pretty close (it’s using the colors from GridView which is pretty close to Windows Explorer) <TreeView …> <TreeView.Resources> <LinearGradientBrush x:Key=”{x:Static SystemColors.HighlightBrushKey}” EndPoint=”0,1″ StartPoint=”0,0″> <GradientStop Color=”#FFD9F4FF” Offset=”0″/> <GradientStop Color=”#FF9BDDFB” Offset=”1″/> </LinearGradientBrush> <LinearGradientBrush x:Key=”{x:Static SystemColors.ControlBrushKey}” EndPoint=”0,1″ StartPoint=”0,0″> <GradientStop Color=”#FFEEEDED” Offset=”0″/> <GradientStop Color=”#FFDDDDDD” Offset=”1″/> </LinearGradientBrush> … Read more