itemscontrol

WPF ItemsControl the current ListItem Index in the ItemsSource

此生再无相见时 提交于 2019-11-27 20:11:44
Is it possible to know the current item's Index in a ItemsControl? EDIT This works! <Window.Resources> <x:Array Type="{x:Type sys:String}" x:Key="MyArray"> <sys:String>One</sys:String> <sys:String>Two</sys:String> <sys:String>Three</sys:String> </x:Array> </Window.Resources> <ItemsControl ItemsSource="{StaticResource MyArray}" AlternationCount="100"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Margin="10"> <!-- one --> <TextBlock Text="{Binding Path=., StringFormat={}Value is {0}}" /> <!-- two --> <TextBlock Text="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource=

Use different template for last item in a WPF itemscontrol

南楼画角 提交于 2019-11-27 19:27:49
I'm using a custom template in my itemscontrol to display the following result: item 1, item 2, item3, I want to change the template of the last item so the result becomes: item 1, item2, item3 The ItemsControl: <ItemsControl ItemsSource="{Binding Path=MyCollection}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" IsItemsHost="True"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Name}"/> <TextBlock Text=", "/> </StackPanel> </DataTemplate> <

How to make WPF wrappanel child items to stretch?

时光毁灭记忆、已成空白 提交于 2019-11-27 17:35:39
问题 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

How to get the index of the current ItemsControl item?

十年热恋 提交于 2019-11-27 17:25:05
问题 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" ... . 回答1: I would suggest looking at: WPF ItemsControl the current ListItem Index in the ItemsSource It explains how to work

Multiple Image in Canvas ItemsControl

纵然是瞬间 提交于 2019-11-27 16:24:40
I want to show multiple image on a canvas. I need to position them differently in the canvas. I made a class for my images : class MapItem:Image { public int DistanceToTop { get; set; } public int DistanceToLeft { get; set; } } My XAML looks like this : <UserControl.DataContext> <Map:MapViewModel/> </UserControl.DataContext> <ItemsControl ItemsSource="{Binding All}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style TargetType="Image"> <Setter Property="Canvas.Left" Value="{Binding DistanceToLeft}

Stretching controls to fill ItemsControl

扶醉桌前 提交于 2019-11-27 15:44:24
问题 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

How to display search results in a WPF items control with highlighted query terms

房东的猫 提交于 2019-11-27 15:11:56
I'd like to display search results within a WPF ItemsControl with the query terms highlighted. The search engine I use, Lucene.Net with the Highlighter plugin, returns strings with the query terms marked up like so: ...these <Bold>results</Bold> were found to be statistically significant... I can instruct the Highlighter plugin to use any set of markup tags to wrap a query term. I'm not limited to the <Bold> tag in the example above. For WPF, I'd likely make these <Run/> elements with a style attached. The challenge is to take the string I've been given and render it as if it were "actual XAML

WPF Dynamic Layout with ItemsControl and Grid

好久不见. 提交于 2019-11-27 11:47:17
I am creating a WPF form. One of the requirements is that it have a sector-based layout so that a control can be explicitly placed in one of the sectors/cells. I have created a tic-tac-toe example below to convey my problem: There are two types and one base type: public class XMoveViewModel : MoveViewModel { } public class OMoveViewModel : MoveViewModel { } public class MoveViewModel { public int Row { get; set; } public int Column { get; set; } } The DataContext of the form is set to an instance of: public class MainViewModel : ViewModelBase { public MainViewModel() { Moves = new

WPF: ItemsControl with scrollbar (ScrollViewer)

时光总嘲笑我的痴心妄想 提交于 2019-11-27 11:16:05
I followed this small "tutorial" on how to add a scrollbar to an ItemsControl, and it works in Designer view, but not when I compile and execute the program (only the first few items show up, and no scrollbar to view more - even when VerticalScrollbarVisibility is set to "Visible" instead of "Auto"). Any idea on how to solve this? This is the code I use to show my items (normally I work with Databinding, but to see the items in my Designer I added them manually): <ItemsControl x:Name="itemCtrl" Style="{DynamicResource UsersControlStyle}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate>

WPF TabStop / TabIndex in ItemsControl

a 夏天 提交于 2019-11-27 07:33:04
问题 I'm dynamically adding WPF ComboBox-es and I want to be able to select the added ComboBoxes with the 'TAB' key . (Dynamically generate TabIndex or something) As it actually is: What I want: How would you do that? This is the code: <ItemsControl ItemsSource="{Binding}" Name="myItemsControl"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Grid