itemscontrol

How to set ItemsPanelTemplate to a dynamically created Grid in code behind

送分小仙女□ 提交于 2019-12-01 17:24:12
I've got this UserControl defined in XAML and would like to set the ItemsPanelTemplate dynamically in my code behind class (not in the XAML like in the example): <UserControl> <ItemsControl x:Name="Items"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid> <!-- I want to add this Grid definition in code behind --> <Grid.ColumnDefinitions> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> </Grid> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </UserControl> I tried something like this.Items.ItemsPanel.Template =

WPF Show data from multiple DataContexts in ToolTip of ItemsControl

陌路散爱 提交于 2019-12-01 16:32:40
I am trying to display a tooltip for an item generated by an ItemsControl that needs to pull data from conceptually unrelated sources. For example, say I have an Item class as follows: public class Item { public string ItemDescription { get; set; } public string ItemName { get; set; } } I can display the Item within an ItemsControl with a tooltip as follows: <ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding ItemName}"> <TextBlock.ToolTip> <ToolTip> <TextBlock Text="{Binding ItemDescription}" /> </ToolTip> <

Find UI element corresponding to an item in a Silverlight ItemsControl

孤街醉人 提交于 2019-12-01 13:02:26
I have a list of strings displayed by a Silverlight ItemsControl. The DataTemplate is a Border control with a TextBlock as its child. How can I access the border control corresponding to an item? For example, I might want to do this to change the background color. An easier way to do this is to grab the Parent of the textblock and cast it as a Border. Here is a quick example of this: Xaml <Grid> <ItemsControl x:Name="items"> <ItemsControl.ItemTemplate> <DataTemplate> <Border> <TextBlock MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave" Text="{Binding}" /> </Border> <

Find UI element corresponding to an item in a Silverlight ItemsControl

霸气de小男生 提交于 2019-12-01 11:36:51
问题 I have a list of strings displayed by a Silverlight ItemsControl. The DataTemplate is a Border control with a TextBlock as its child. How can I access the border control corresponding to an item? For example, I might want to do this to change the background color. 回答1: An easier way to do this is to grab the Parent of the textblock and cast it as a Border. Here is a quick example of this: Xaml <Grid> <ItemsControl x:Name="items"> <ItemsControl.ItemTemplate> <DataTemplate> <Border> <TextBlock

Limit the number of rows displayed in Items control

痴心易碎 提交于 2019-12-01 09:31:15
Is there a way to limit the number of rows that get displayed in items control. ? I have a observable collection of strings which are bound to Items control. I want to limit the number of rows to display to only one. The collection can have more than one. Thanks, Let's say your ItemsSource is set to MyObservableCollection . Well, what if you change your ItemsSource so that it is pointing a MyOneItemCollection instead? Then, just use LINQ to do something like this: using System.Linq; MyOneItemCollection = MyObservableCollection.First(); or using System.Linq; MyOneItemCollection =

Limit the number of rows displayed in Items control

感情迁移 提交于 2019-12-01 09:01:48
问题 Is there a way to limit the number of rows that get displayed in items control. ? I have a observable collection of strings which are bound to Items control. I want to limit the number of rows to display to only one. The collection can have more than one. Thanks, 回答1: Let's say your ItemsSource is set to MyObservableCollection . Well, what if you change your ItemsSource so that it is pointing a MyOneItemCollection instead? Then, just use LINQ to do something like this: using System.Linq;

Virtualizing Panel that doesn't crop items

喜你入骨 提交于 2019-12-01 06:33:07
So, it looks really silly to have a chrome-less collection if the items are getting cut/cropped at the end of the scroll region. I want to create a virtualizing panel for collections (ItemsControl/ListBox) that only draws whole items, never pieces of items. For example: ______________ | | |______________| ______________ | | |______________| ______________ | | I don't want the 3rd partial container to be displayed unless there is room for the WHOLE item/container to be displayed. In the examples, the third item was cropped because of a lack of space. Any suggestions? Should I try to reinvent

Scroll a new item in a ItemsControl into view

↘锁芯ラ 提交于 2019-12-01 04:15:45
I have an ItemsControl that is databound to a ObservableCollection . I have this method in the code behind which adds a new model to the list. I would then like to scroll the new item (at the bottom of the list) into view. I think the size of the ItemsControl is not yet updated when I am querying the size, since the ActualHeight before and after the addition of the model is the same. The effect of this code is to scroll to a point slightly above the new item. How would I know what the new ActualHeight is going to be? Here is my code: ViewModel.CreateNewChapter(); var height = DocumentElements

WPF UserControl in DataTemplate within ItemsControl - how to bind to parent of ItemsSource

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 03:58:01
The subject line says it all really! I have a user control which can be bound successfully to, say, a Fullname object - i.e. it works ok. I now need to show a list of these and, again, this works ok when the control is in a DataTemplate within ItemsControl.Template. But, the control has a property (InEditMode) that is not a property of the Fullname object but of the object that has the FullnameList property to which the ItemsControl is bound, via ItemsSource. This InEditMode property works fine when the control is not in a list and is bound to parent sibling properties named, say,

How do I use UI Automation on a WPF ItemsControl that groups items?

一个人想着一个人 提交于 2019-12-01 03:54:15
问题 I am using Microsoft UI Automation (i.e. AutomationElement) to run automated acceptance tests against my application. This has gone well, but I've hit a situation that doesn't appear to be exposed to the automation framework. I have an ItemsControl (although I could be using one of its derived controls, e.g. ListBox) and I am using CollectionViewSource to group items. Here is a complete window to demonstrate: <Window x:Class="GroupAutomation.Window1" xmlns="http://schemas.microsoft.com/winfx