selecteditem

Combo Box Size Issue After All Items Are Removed

橙三吉。 提交于 2019-12-19 08:11:55
问题 My application contains a ComboBox that the user can delete items from. When the program starts up it populates the ComboBox from a list of strings read in from a configuration file. Here is the code to add items: // version list is an array of strings foreach (string version in versionList) { versionComboBox.Items.Add(version); } if (versionComboBox.Items.Count > 0) { versionComboBox.SelectedIndex = 0; } Here is a screenshot of the combo box after it's been populated: If the user clicks the

WPF ListBox - Getting UIElement instead of of SelectedItem

血红的双手。 提交于 2019-12-19 05:13:17
问题 I created a ListBox that has a DataTemplate as Itemtemplate . However, is there an easy way to access the generated UIElement instead of the SelectedItem in codebehind? When I access SelectedItem , I just get the selected object from my ItemsSource collection. Is there a way to access the UIElement (ie. the element generated from the DataTemplate together with the bound object)? 回答1: You are looking for the ItemContainerGenerator property. Each ItemsSource has an ItemContainerGenerator

WPF ComboBox SelectedItem

醉酒当歌 提交于 2019-12-18 16:31:41
问题 Ok been working with WPF for a while but I need some help. I have a ComboBox like below: <TabControl> <TabItem Header="1"> <ComboBox ItemsSource="{Binding MyList}" SelectedItem="{Binding MyListSelection}"/> </TabItem> <TabItem Header="2"/> </TabControl> Whenever I move away from tab 1 and then come back to it the selection gets removed. I think the reason for that is that the controls get destroyed when they go out of scope and then back in. But in the process of that the SelectedItem becomes

Find control inside Listbox.ItemTemplate (WPF C#)

你离开我真会死。 提交于 2019-12-18 13:39:28
问题 I have some problems finding the right TextBlock control inside a StackPanel . My markup: <ListBox Name="lstTimeline" ItemContainerStyle="{StaticResource TwItemStyle}" MouseDoubleClick="lstTimeline_MouseDoubleClick"> <ListBox.ItemTemplate> <DataTemplate> <DockPanel MaxWidth="{Binding ElementName=lstTimeline, Path=ActualWidth}"> <Border Margin="10" DockPanel.Dock="Left" BorderBrush="White" BorderThickness="1" Height="48" Width="48" HorizontalAlignment="Center"> <Image Source="{Binding

Get selected item in DropDownList ASP.NET MVC

喜你入骨 提交于 2019-12-18 05:20:31
问题 I know there are multiple threads on how to get the selected value of a DropDownList. However I can't find the right way to get this value from a partial view in my controller. This is my partial view: @model List<aptest.Models.answer> @Html.DropDownList("dropdownlist", new SelectList(Model, "text", "text")) <button type="submit">next</button> 回答1: In order to get dropdown value, wrap your select list in a form tag. Use models and DropDownListFor helper Razor View @model MyModel @using (Html

Combobox SelectedItem doesn't update when source changes

倾然丶 夕夏残阳落幕 提交于 2019-12-18 04:49:09
问题 I have a viewmodel which implement INotifyPropertyChanged . On this viewModel is a property called SubGroupingView . This property is bound to the selected item of a combo box. When i change the combo box, the source property is being updated fine, but when I change the source property or when the control is initialized, the combobox.selectedItem is NOT reflecting what exists in the property. Here is some code to get you started: <ComboBox Grid.Column="3" Grid.Row="1" Margin="0,1,4,1"

WPF ListView SelectedItem is null

时光毁灭记忆、已成空白 提交于 2019-12-17 12:59:13
问题 I have a Listview that has a checkbox as one of the columns. If I click anywhere but the actual checkbox the SelectedItem of the ListView is set to the current selected row, as expected. If, on the other hand I click onto the checkbox (without clicking on the row first) then the SelectedItem is null or the previously clicked row. Can anyone help me out.... Cheers <ListView Width="auto" SelectionMode="Single" x:Name="listBox" ItemsSource="{Binding MyData}" SelectedItem="{Binding Path

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

假如想象 提交于 2019-12-17 04:59:09
问题 I Have a wpf Listbox that display's a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select the listbox item. Is there some property I need to set for the Textbox to forward the click event to the Listbox? 回答1: 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

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

扶醉桌前 提交于 2019-12-17 04:58:38
问题 I Have a wpf Listbox that display's a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select the listbox item. Is there some property I need to set for the Textbox to forward the click event to the Listbox? 回答1: 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

Setting selected item in combobox bound to dictionary

无人久伴 提交于 2019-12-14 03:51:42
问题 I have a combobox that is bound to a dictionary like this: Dictionary<int, string> comboboxValues = new Dictionary<int, string>(); comboboxValues.Add(30000, "30 seconds"); comboboxValues.Add(45000, "45 seconds"); comboboxValues.Add(60000, "1 minute"); comboBox1.DataSource = new BindingSource(comboboxValues , null); comboBox1.DisplayMember = "Value"; comboBox1.ValueMember = "Key"; I'm getting the key from the SelectedItem like this: int selection = ((KeyValuePair<int, string>)comboBox1