itemscontrol

How to highlight selected item in ItemsControl?

末鹿安然 提交于 2019-11-27 05:59:17
问题 I have the following XAML. How can i highlight the selected item in the ItemsControl ? I can override the selected item template for ListView but how to achieve the same for ItemsControl? Is there any alternative control that can display a collection of images ? <Window x:Class="ImageScrollDemo.View.MoviePosterView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ImageScrollDemo" xmlns:i="clr

Style within DataTemplate is only being applied to the last item in ItemsControl?

我的梦境 提交于 2019-11-27 05:56:13
问题 In the XAML below, I have an ItemsControl that has three DataObjects. I use a DataTemplate to display DataObjects as Buttons with an "X" on them. The Button uses a Style to set its Content. If the Setter.Value is "X", everything works great! However, if I change the Setter.Value to a TextBlock whose TextProperty is "X", the X only appears on the last Button (the third DataObject) and the first two Buttons are empty. Is this a bug, or can anybody explain why this happens? Note 1) This is a

WPF - Bind to Item Index from within ItemTemplate of ItemsControl?

跟風遠走 提交于 2019-11-27 04:23:10
Is there a way to bind to the ItemIndex from within the ItemTemplate of an ItemsControl? For example: <ItemsControl ItemsSource="{Binding Path=ItemList}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=ThisItemsIndex}" /> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> John Bowen If you're not using any type of alternating row styles you might be able to hijack the AlternationIndex for this. Set AlternationCount on your ItemsControl to something greater than the max possible count of your items and then use Text="{Binding RelativeSource={RelativeSource

Use different template for last item in a WPF itemscontrol

心不动则不痛 提交于 2019-11-27 04:22:47
问题 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=

WrapPanel as ItemPanel for ItemsControl

℡╲_俬逩灬. 提交于 2019-11-27 04:13:06
Still fooling around with WPF and learning as I go. Trying now to build a dynamic grouping of controls (mostly Buttons but might include CheckBoxes and others). I had no idea what was the best way to do this so I tried creating a ItemsControl style and then add the items into a ItemsPresenter inside a WrapPanel. Soon realized the items wouldn't wrap because they effectively weren't inside the WrapPanel unless I put it as ItemsHost. Like this: <Style x:Key="ButtonPanelGroup" TargetType="{x:Type ItemsControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type

ItemsControl Drag and Drop

折月煮酒 提交于 2019-11-27 02:52:36
问题 I have an ItemsControl with a DataTemplate that is bound to an ObservableCollection of integers. <ItemsControl Name="DimsContainer" ItemTemplate="{StaticResource DimensionsTemplate}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> And in the Windows Resources: <Window.Resources> <DataTemplate x:Key="DimensionsTemplate" > <TextBlock Text="{Binding}" Padding="5" VerticalAlignment="Center"

Bind to ItemsControl's DataContext from inside an ItemTemplate

回眸只為那壹抹淺笑 提交于 2019-11-27 01:49:16
I have an ItemsControl whose for the ItemTemplate DataTemplate contains a Button. I want the Command on the button to bind to a Command on the DataContext of the ItemsControl, not the ItemTemplate. I think the solution has to do with using RelativeSource, but my attempts so far have failed: <ItemsControl ItemsSource="{Binding Games}"> <ItemsControl.ItemTemplate> <DataTemplate> <Button Command="{Binding Path=GameSelectedCommand, Source={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}" Style="{StaticResource MenuButtonStyle}" Content="{Binding Name}

How to programmatically select an item in a WPF TreeView?

橙三吉。 提交于 2019-11-27 01:06:47
How is it possible to programmatically select an item in a WPF TreeView ? The ItemsControl model seems to prevent it. Steven Robbins It's a real pain for some strange reason, you have to use ContainerFromItem to get the container, then invoke the select method. // selectedItemObject is not a TreeViewItem, but an item from the collection that // populated the TreeView. var tvi = treeView.ItemContainerGenerator.ContainerFromItem(selectedItemObject) as TreeViewItem; if (tvi != null) { tvi.IsSelected = true; } There once was a blog entry on how to do it here , but the link is dead now. kuninl For

How to use AlternationIndex in ItemsControls?

时光毁灭记忆、已成空白 提交于 2019-11-27 00:43:40
问题 I have seen some articles that show how to use AlternationIndex with ListBox es or ListView s, but I had spent a few hours trying to get alternating background colors on the base ItemsControl class and nothing seems to work. All ListBox samples I saw use ListBoxItem as the target type for the style that sets the background based on AlternationIndex - like this one from MSDN: <Grid> <Grid.Resources> <Style x:Key="alternatingWithTriggers" TargetType="{x:Type ListBoxItem}"> <Setter Property=

How to get a List<string> collection of values from app.config in WPF?

蓝咒 提交于 2019-11-27 00:16:40
The following example fills the ItemsControl with a List of BackupDirectories which I get from code. How can I change this so that I get the same information from the app.config file? XAML: <Window x:Class="TestReadMultipler2343.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"/> <ColumnDefinition