itemscontrol

WPF Canvas-based ItemsControl with minimum recycled items?

自作多情 提交于 2019-12-08 11:35:32
问题 I'm using an ItemsControl with a Canvas as its backing Panel . I often need to .Clear() the ObservableCollection is the ItemsControl's ItemSource , and then add new information to it, which causes all the controls to be destroyed and new UserControl s to be created, which is very sluggish. How can I force the ItemsControl to retain a certain amount of containers even after I call .Clear(), and then reuse them when new items are added to the ItemSource? 回答1: I am not sure how efficient this

get ItemsControl in ItemCollection CollectionChanged event

时光怂恿深爱的人放手 提交于 2019-12-08 04:48:43
问题 my itemscontrol : <ItemsControl x:Name="MyItemsControl" Style="{StaticResource ItemsControlStyle}" /> <Style TargetType="{x:Type ItemsControl}" x:Key="ItemsControlStyle"> <Setter Property="ItemTemplate" Value="{StaticResource ItemsControlDataItem}"></Setter> </Style> <DataTemplate x:Key="ItemsControlDataItem" > <Ellipse Width="45" Height="45"></Ellipse> </DataTemplate> iv'e hooked an event to see when the underlying collection as changed : ((INotifyCollectionChanged)MyItemsControl.Items)

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

为君一笑 提交于 2019-12-07 07:34:02
问题 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

Using StackPanel as ContentControl (WPF)

北战南征 提交于 2019-12-07 05:07:59
问题 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

WPF: How to create a custom items control panel?

雨燕双飞 提交于 2019-12-07 04:58:31
问题 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

How to increase padding displayed items combobox?

若如初见. 提交于 2019-12-07 01:19:50
问题 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. 回答1: You can use ItemContainerStyle to apply a style to the ComboBoxItems that sets properties such as

Separator in ItemsControl renders in different shades for each item

蹲街弑〆低调 提交于 2019-12-07 00:57:27
I have an ItemsControl presenting TextBlocks, with a Separator at the bottom of each item. My problem is that each Separator is rendered in a slightly different shade of gray - it looks really dodgy: Here is my XAML: <ItemsControl ItemsSource="{Binding Path=Items}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel></StackPanel> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding}" ></TextBlock> <Separator></Separator> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> I have also

DataContext not set when using View as DataTemplate in ItemsControl

自作多情 提交于 2019-12-06 04:25:02
I have an ObservableCollection of ViewModels that I'd like to bind to an ItemsControl containing the associated child Views. When I add ViewModels to my collection, an appropriate number of child Views are generated in the ItemsControl. However, the DataContext for each of the generated views is null. If I inline my child view, it works correctly. So, what do I need to do to set the DataContext for my child views to my ViewModels? Here's the relavent bits in my parent ViewModel: public ObservableCollection<ChildViewModel> Numbers { get; set; } public ParentViewModel() { Numbers = new

Wrap something around each item in an ItemsControl

岁酱吖の 提交于 2019-12-06 02:52:18
问题 Let's say I have a collection of objects of different classes. Each class has its UserControl DataTemplated in a resource file. Now I want to use ItemsControl to display the collection, but I want an Border or Expander around each item. I would expect something like this to work: <ItemsControl ItemsSource="{Binding MyObjects}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate>

Itemscontrol that arrange Items with Gridsplitter-Functionality

天大地大妈咪最大 提交于 2019-12-05 18:23:20
I need a layout that stacks Items horizontal or vertical. Each Item should be separated by a Splitter, so the User can change the Size (Like the Toolbox Container in VisualStudio) The Items come from a Model, so I need a ItemsControl where I can set the ItemsSource. My first idea was to build a CustomControl derived from Grid. Their I used the "OnVisualChildrenChanged" Method to react when a new Item is added. Then I wantet to add new Column-/Rowdefinitions (Depending wether it schould be horizontal or vertical). But here was the first Proplem. When the Grid is set to IsItemsHost="true" I get