itemtemplate

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=

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=

Add Columns dynamically to Grid-view with itemtemplate

▼魔方 西西 提交于 2019-11-28 08:46:12
问题 i want to know how to add column dynmically to gridview. the grid view suppose to get user input. i know how to use itemtemplate for specific no of columns, but i'm not aware how to add columns dynamically with itemtemplate (textbox) fields and make databind. 回答1: You need to create a class implementing ITemplate , Full code as following: public class DynamicTemplateField : ITemplate { public void InstantiateIn(Control container) { //define the control to be added , i take text box as your

Change style of last item in ListBox

我与影子孤独终老i 提交于 2019-11-28 00:04:14
I have listbox control which has list of colors. Here is code and Image: <ListBox Name="FillSelections" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Center" SelectedItem="{Binding SelectedColor}" SelectionMode="Single" Style="{StaticResource HorizontalListBoxStyle}" ItemsSource="{Binding FillColors}" ItemTemplate="{StaticResource ColorsItemTemplate}"></ListBox> <DataTemplate x:Key="ColorsItemTemplate"> <Border BorderBrush="Transparent"> <Rectangle Width="20" StrokeThickness="1" Stroke="Black"> <Rectangle.Fill> <SolidColorBrush Color="{Binding}" /> </Rectangle.Fill> <

Display multiple types from a single list in a WPF ListBox?

﹥>﹥吖頭↗ 提交于 2019-11-27 16:16:54
问题 I have an ObservableCollection<Object> that contains two different types. I want to bind this list to a ListBox and display different DataTemplates for each type encountered. I can't figure out how to automatically switch the data templates based on the type. I have attempted to use the DataType property of the DataTemplate and attempted using ControlTemplates and a DataTrigger, but to no avail, either it nothing shows up, or it claims it can't find my types... Example Attempt below: I only

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

女生的网名这么多〃 提交于 2019-11-27 10:07:32
问题 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>

Different item template for each item in a WPF List?

我只是一个虾纸丫 提交于 2019-11-26 23:14:29
问题 I have many items inside a list control. I want each item to have a different item template depending on the type of the item. So the first item in the list is a ObjectA type and so I want it to be rendered with ItemTemplateA. Second item is a ObjectB type and so I want it to have ItemTemplateB for rendering. At the moment I can only use the ItemTemplate setting to define one template for them all. Any way to achieve this? 回答1: the ItemTemplateSelector will work but I think it is easier to