itemscontrol

Update ItemsControl when an item in an ObservableCollection is updated

独自空忆成欢 提交于 2019-12-05 17:30:42
问题 The Problem: You declare an ItemsControl ( or a control derived from ItemsControl ) in the view. You bind the ItemsControl.ItemsSource property to an ObservableCollection in your ViewModel. Your view updates as expected when an item is added to /removed from the ObservableCollection . BUT, the view does not update when you change a property of an item in the ObservableCollection . Background: It seems that this is a common problem many WPF developers have encountered. It has been asked a few

How to focus a datatemplated TextBox in the first element of an ItemsControl in a Window, when the Window is opened? (C#, WPF)

廉价感情. 提交于 2019-12-05 15:13:56
When the user clicks a button in the application, a window opens up. I want the TextBox belonging to the first item in the ItemsControl to be focused, so that the user can start typing as soon as the Window is opened, without needing to manually select the TextBox. How can this be done? For simplicity, we can say that the Window looks approximately like this: <Window> <Grid> <ItemsControl ItemsSource="{Binding MyItems}"> <DataTemplate> <Grid> <StackPanel> <StackPanel> <customControls:ValidationControl> <TextBox Text="" /> </customControls:ValidationControl> </StackPanel> </StackPanel> </Grid>

How can I retrieve the DataTemplate (and specific objects) of an item in an ItemsControl?

有些话、适合烂在心里 提交于 2019-12-05 13:33:59
I have seen solutions to a very similar issue, yet it doesn't translate to mine. (Namely, this article: http://blogs.msdn.com/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx ) My ItemsControl is bound to an observable collection, which can have items dynamically added to it. When I add an item to the observable collection, the templated item renders properly in my itemscontrol, but I can't figure out how to access it. My my observable colleciton changed code, I am trying to access information about. I am using a custom

WPF: How to create a custom items control panel?

删除回忆录丶 提交于 2019-12-05 10:35:32
I want to design a custom items control panel for a ListBox . There are 3 requirements: It should have the properties int rows and int columns which would define the matrix of cells that the panel is made of. This is what the panel should look like (colors are irrelevant, I just wanted to show that the panel is consisted of 12 empty cells in a 3x4 matrix): If the number of items in the items control is less than the number of defined cells all the cells should be drawn. E.g. if there are only 4 items to be placed in a 3x4 matrix shown in the picture, all of the cells should be drawn and only 4

Using StackPanel as ContentControl (WPF)

被刻印的时光 ゝ 提交于 2019-12-05 10:30:57
So I have a StackPanel that I am using as a ContentControl. I have a place where I want buttons to be generated based on data that I am binding to, and that is all working good, but I want the buttons to be laid out horizontally, not vertically as is what is currently happening. Here's a screenshot: And here is the code from my ContentTemplate description: <StackPanel Name="wpReleaseButtons" Orientation="Horizontal" Grid.Row="2"> <ItemsControl IsTabStop="False" ItemsSource="{Binding Path=BranchCommands}"> <ItemsControl.ItemTemplate> <DataTemplate> <Button Tag="{Binding}" Padding="3">

WPF GridViewRowPresenter in an ItemsControl

依然范特西╮ 提交于 2019-12-05 09:56:21
I'm just starting learning WPF and I'm trying to use a GridViewRowPresenter inside of an ItemsControl to essentially duplicate the functionality of a simple table in HTML. The ListView is not appropriate since it is interactive (which I don't want). I am binding to a generic List of objects of an unknown quantity. I have a List of a custom object that has two string properties: FirstName and LastName. The following code works: <ItemsControl Name="myItemsControl"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=FirstName}"/> </DataTemplate> </ItemsControl.ItemTemplate>

WPF - Creating a custom ItemsControl

孤人 提交于 2019-12-05 06:08:15
问题 I'm looking into creating custom controls for WPF and I've found some reasonably useful blogs and such that vaguely go into enough detail but I'm still struggling a bit. Basically, what I'm trying to create is something akin to the infamous 'Coda Slider' but i just don't know enough to get started properly. Can anyone either point me in the direction of someone/somewhere to give me the low-down on creating custom ItemControls or provide me with the basic information like what ItemsControl

How to increase padding displayed items combobox?

人走茶凉 提交于 2019-12-05 05:42:24
I want to write XAML template of a combobox to increase the spaces/padding between items. I searched for this but almost end up with the ItemsPresenter: <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> How can I format the item (border, padding, font...) using this template? Please help. You can use ItemContainerStyle to apply a style to the ComboBoxItems that sets properties such as padding: <ComboBox ItemsSource="{Binding}"> <ComboBox.ItemContainerStyle> <Style TargetType="ComboBoxItem">

ItemsControl, VirtualizingStackPanel and ScrollViewer height

守給你的承諾、 提交于 2019-12-05 02:52:21
I want to display a important list of items using an ItemsControl. The reason why I'm using an ItemsControl is that the DataTemplate is much more complex in the application I'm working on: The sample code provided only reflects the sizing problem I have. I would like : the ItemsControl to be virtualized because there is many items to display its size to expand to its parent container automatically (the Grid) <Grid> <ItemsControl x:Name="My" ItemsSource="{Binding Path=Names}"> <ItemsControl.Template> <ControlTemplate> <StackPanel> <StackPanel> <TextBlock Text="this is a title" FontSize="15" />

ListBox Grouping issue

一曲冷凌霜 提交于 2019-12-05 02:43:09
I am trying to Group my collection which is based on my following model: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public Role PersonRole { get; set; } } public class Role { public int Id { get; set; } public string RoleName { get; set; } } My PersonCollection, public ObservableCollection<Person> PersonList; The collection is populated with three Person object, two with identical roles. I want to group all my persons as per their RoleName. I have the following XAML: <Grid.Resources> <CollectionViewSource x:Key="cvs" Source="{Binding