itemscontrol

ItemsControl ItemTemplate Binding

痞子三分冷 提交于 2019-11-29 13:10:49
In WPF4.0, I have a class that contains other class types as properties (combining multiple data types for display). Something like: public partial class Owner { public string OwnerName { get; set; } public int OwnerId { get; set; } } partial class ForDisplay { public Owner OwnerData { get; set; } public int Credit { get; set; } } In my window, I have an ItemsControl with the following (clipped for clarity): <ItemsControl ItemsSource={Binding}> <ItemsControl.ItemTemplate> <DataTemplate> <local:MyDisplayControl OwnerName={Binding OwnerData.OwnerName} Credit={Binding Credit} /> </DataTemplate> <

How do I access the children of an ItemsControl?

天涯浪子 提交于 2019-11-29 11:24:53
问题 If i have a component derived from ItemsControl , can I access a collection of it's children so that I can loop through them to perform certain actions? I can't seem to find any easy way at the moment. 回答1: A solution similar to Seb's but probably with better performance : for(int i = 0; i < itemsControl.Items.Count; i++) { UIElement uiElement = (UIElement)itemsControl.ItemContainerGenerator.ContainerFromIndex(i); } 回答2: See if this helps you out: foreach(var item in itemsControl.Items) {

Modify ZIndex of an Items in an ItemsControl

孤人 提交于 2019-11-29 10:37:55
Here is the code of my ItemsControl that zooms on items when the mouse goes over. I don't manage to increase the ZIndex of the current zoomed item to put it over the others. <ItemsControl ItemsSource="{Binding Path=Value}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Name}" RenderTransformOrigin="0.5 0.5"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="RenderTransform"> <Setter.Value> <ScaleTransform ScaleX="1.5" ScaleY="1.5" /> </Setter.Value> </Setter> </Trigger> </Style

WPF - Best way to remove an item from the ItemsSource

我们两清 提交于 2019-11-29 04:52:46
I'm writing a custom ItemsControl (a tabbed document container), where each item (tab) can remove itself from the UI when the user closes it. However, I can't remove it directly from the ItemsControl.Items collection, because the items can be databound. So I have to remove it from the ItemsSource , which can be anything ( ICollection , DataTable , DataSourceProvider ...). In the context of my application, I know what the actual type of the ItemsSource will be, but I want that control to be more generic so that I can reuse it later. So I'm looking for a way to remove an item from a data source,

ItemsControl.ItemsSource MVVM performance

孤人 提交于 2019-11-29 04:01:16
问题 I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel instances. Now once the large amount Model instances is loaded all the ViewModel complemnents needs to be added to that ObservableCollection. How can I add a large amount of ViewModels without making the UI Thread hang? I suppose the UI Thread hangs because each time a new item is added the ItemsControl needs to update itself and does layout etc. over and over again. Should I suspend

How to make WPF wrappanel child items to stretch?

北城余情 提交于 2019-11-29 03:32:42
I'd like to create an ItemsControl where child items are placed like a WrapPanel , but child Items should take as much space as it can. So that when the window size gets larger or smaller, the child items should stretch according to a certain width:height ratio. When the child items get added or removed from the ItemsControl 's ItemsSource , the WrapPanel should place linebreaks among items appropriately to keep child item's width:height ratio. Below is what I have so far. Is it possible to do this in Xaml? or should I create a custom control for this? Thanks in advance! <Window> <Grid>

When using ItemsControl ItemsControl.ItemsPanel is set to Canvas, ContenPresenter comes in and break my Canvas properties on the children [WPF]

走远了吗. 提交于 2019-11-29 03:29:21
I am using an ItemsControl where the ItemsPanel is set to Canvas (see this question for more background information). The ItemsControl is performing as I want, and it works like a charm when adding a child element manually by putting it into ItemsControl.Items: <ItemsControl> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas IsItemsHost="True" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.Items> <Button Canvas.Left="500" Content="Button Text" /> </ItemsControl.Items> </ItemsControl> Note the Canvas.Left property on the Button. This works like a charm, and the Button is

How to get the index of the current ItemsControl item?

时光毁灭记忆、已成空白 提交于 2019-11-29 03:18:22
Is there any way to get the index of the current ItemsControl item in WPF ? For example, I want to do something like: <ItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <TextBox Text="{Binding current_index}"> </TextBox> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> so that after this, the first TextBox will show text "0" , second "1" , third "2" ... . FishySwede I would suggest looking at: WPF ItemsControl the current ListItem Index in the ItemsSource It explains how to work around the fact that there isn't a built in Index property on the ItemsControl. EDIT: I tried the

WPF drag and drop from a ListBox that has SelectionMode=Extended

混江龙づ霸主 提交于 2019-11-29 02:25:36
I have a ListBox and want the selection-mode to be extended. Also I want have to implement drag and drop functionality. The problem now is, that if the mouse is clicked on a selected item, it will be immediately be selected as single selection instead of waiting to the mouse-up-event for doing this. Due to this behaviour, start dragging multiple items is for the user quasi impossible because always he clicks on the selection to start dragging, the selection changes to the item that is under the mouse and starts the drag-operation with this item. Is there a good workaround for this problem or

Stretching controls to fill ItemsControl

社会主义新天地 提交于 2019-11-29 01:11:26
I am attempting to write a simple WPF learning project which creates a set of buttons inside a resizeable main window. There is to be one Button per entry in a collection, and the contents of that collection may vary during run-time. I want the buttons to fill the entire window (e.g. 1 button @ 100% width, 2 buttons @ 50% width, 3 buttons @ 33% width, etc. all at 100% height). A simplified version of what I've written so far is: <ItemsControl x:Name="itemscontrolButtons" ItemsSource="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <Button Tag="{Binding}"> <TextBlock Text="{Binding}" />