listbox

Inline editing TextBlock in a ListBox with Data Template (WPF)

孤街醉人 提交于 2019-11-28 18:28:30
Using WPF, I have a ListBox control with a DataTemplate inside it. The relevant XAML code is shown below: <ListBox Name="_todoList" Grid.Row="1" BorderThickness="2" Drop="todoList_Drop" AllowDrop="True" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="4"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <CheckBox Grid.Column="0" Checked="CheckBox_Check" /> <TextBlock Name="descriptionBlock" Grid.Column="1" Text="

What's the difference between ItemTemplate and ItemContainerStyle in a WPF ListBox?

梦想的初衷 提交于 2019-11-28 18:10:43
In WPF Listbox , I'm confused with these 2 notions: ItemTemplate and ItemContainerStyle Can someone explain me more? The ItemTemplate is for styling how the content of your data item appears. You use it to bind data fields, format display strings, and so forth. It determines how the data is presented. The ItemContainerStyle is for styling the container of the data item. In a list box, this would be a ListBoxItem. Styling here affects things like selection behavior or background color. It determines style and UX of the display. The MSDN page for ItemContainerStyle, linked above, has a pretty

How can I make a column in a listbox in WPF the same width for all items?

让人想犯罪 __ 提交于 2019-11-28 16:59:11
I have a ListBox with an ItemTemplate consisting of a TextBlock and a ComboBox . The problem is that the width of the text inside the TextBlock is not the same for each item and the ComboBox controls are not aligned. How can I set the TextBlock in the template so all items are the same width, that is the one of the widest? Here is my xaml: <ListBox MinHeight="100" ItemsSource="{Binding Trainees}"> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="1"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock VerticalAlignment="Center" Grid.Column=

WPF Listbox Show Button in ItemTemplate on MouseOver

試著忘記壹切 提交于 2019-11-28 16:28:56
问题 I have a listbox containing and image and a button. By default the button is hidden. I want to make the button visible whenever I hover over an item in the listbox. The XAML I am using is below. Thanks <Window.Resources> <Style TargetType="{x:Type ListBox}"> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <Border BorderBrush="Black" BorderThickness="1" Margin="6"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding Path=FullPath}" Height="150" Width="150"/> <Button x

two itemtemplates for one listbox

被刻印的时光 ゝ 提交于 2019-11-28 16:27:23
问题 I've got a class FruitViewModel . It describes ViewModels for ListBox items. <ListBox ItemsSource="{Binding Fruits}"> And I've got class BananaViewModel : FruitViewModel and class AppleViewModel : FruitViewModel Fruits contains BananaViewModel s and AppleViewModel s which is bound to ItemsSource . How can I make different templates for apples and bananas? They should be in one list but have different templates 回答1: You can define DataTemplates that apply to any instance of a specific type by

WPF Trigger for IsSelected in a DataTemplate for ListBox items

狂风中的少年 提交于 2019-11-28 16:03:53
I have a listbox, and I have the following ItemTemplate for it: <DataTemplate x:Key="ScenarioItemTemplate"> <Border Margin="5,0,5,0" Background="#FF3C3B3B" BorderBrush="#FF797878" BorderThickness="2" CornerRadius="5"> <DockPanel> <DockPanel DockPanel.Dock="Top" Margin="0,2,0,0"> <Button HorizontalAlignment="Left" DockPanel.Dock="Left" FontWeight="Heavy" Foreground="White" /> <Label Content="{Binding Path=Name}" DockPanel.Dock="Left" FontWeight="Heavy" Foreground="white" /> <Label HorizontalAlignment="Right" Background="#FF3C3B3B" Content="X" DockPanel.Dock="Left" FontWeight="Heavy" Foreground=

How can I assign the value selected in a listbox to an enum var?

China☆狼群 提交于 2019-11-28 14:50:46
I want to avoid the kludginess of: private void listBoxBeltPrinters_SelectedIndexChanged(object sender, System.EventArgs e) { string sel = string listBoxBeltPrinters.SelectedItem.ToString(); if (sel == "Zebra QL220") { PrintUtils.printerChoice = PrintUtils.BeltPrinterType.ZebraQL220; } else if (sel == "ONiel") { PrintUtils.printerChoice = PrintUtils.BeltPrinterType.ONiel; } else if ( . . .) } Is there a way I can more elegantly or eloquently assign to an enum based on a list box selection, something like: PrintUtils.printerChoice = listBoxBeltPrinters.SelectedItem.ToEnum(PrintUtils

CheckBox inside ListBox

烈酒焚心 提交于 2019-11-28 14:45:37
How to add checkbox inside the listbox. Where ChechBoxList controls is not good for more records, By using listbox user can easily scroll to choose the item. Geetha. Rob Cooper What you want is the CheckBoxList . Newer CheckBoxList Pretty nice step-by-step here . Asad Butt what about checkedListBox ? <asp:CheckBoxList id="checkboxlist1" runat="server"> <asp:ListItem>Item 1</asp:ListItem> <asp:ListItem>Item 2</asp:ListItem> <asp:ListItem>Item 3</asp:ListItem> </asp:CheckBoxList> To access items on user action void checkboxlist1_Clicked(Object sender, EventArgs e) { if (checkBoxList1

Custom listbox sorting

北城余情 提交于 2019-11-28 14:14:39
I need to sort the data contained within a number of listboxes. The user will be able to select between two different types of sorting using radio boxes, one of which is checked by default on form load. I have created the IF statements needed in order to test whether the checked condition is true for that radio button. but i need some help to create the custom sort algorithms. Each list with contain similar looking data, the only difference in the prefix with which each line starts. For example each line in the first listbox starts with the prefix "G30" and the second listbox will be "G31" and

Populate ListBox with a IEnumrable on another thread (winforms)

ぃ、小莉子 提交于 2019-11-28 14:12:33
问题 I'm wondering what would be the best way to populate a ListBox control of a WinForm, populated depending on a radio btn? I have seen some suggestions to use a foreach to loop over each object of my list, and Add() them to the listBox.items.Add(), but this seems to be a really bad idea, since the list from rabio btn 1 returns a list with 10.000 records (takes quiet some time to loop over, and the UI freeze while looping, bad bad idea). Is there any better way to do this, and maybe in a