How to use AlternationIndex in ItemsControls?

The ItemContainerStyle is applied to the elements generated by the ItemsControl: ContentPresenter. The ContentPresenter will in turn contain whatever you put in your ItemTemplate. In the case of a ListBox, the ItemContainerStyle is applied to the generated ListBoxItem. The AlternationCount is, based on what you posted, only available on these generated items. You cannot use … Read more

WrapPanel as ItemPanel for ItemsControl

You might want to take a look at the ItemsPanel property: Gets or sets the template that defines the panel that controls the layout of items. Example: <ItemsControl> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> And you can set it in a Style as follows: <Style TargetType=”ItemsControl”> <Setter Property=”ItemsPanel”> <Setter.Value> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </Setter.Value> … Read more

What exactly does Panel.IsItemsHost do?

Say I have an ItemsControl. I want to use a custom panel that swoops items in and out as you scroll; its called a SwoopPanel. Now, how do I tell the ItemsControl to use my SwoopPanel to contain the templates it creates? The quick way is to set the ItemsPanel on the ItemsControl: <ItemsControl.ItemsPanel> <ItemsPanelTemplate> … Read more

WPF: Alternating colors on a ItemsControl?

Check here http://www.codeproject.com/Articles/35886/WPF-ItemsControl-with-alternating-items-and-hover-.aspx You have to change your code like this to get it working <ItemsControl ItemsSource=”{Binding DataList}” AlternationCount=”2″> <ItemsControl.ItemTemplate> <DataTemplate> <Grid x:Name=”FooBar” Margin=”0,0,0,10″> —————————- —————————- </Grid> <DataTemplate.Triggers> <Trigger Property=”ItemsControl.AlternationIndex” Value=”0″> <Setter Property=”Background” Value=”Blue” TargetName=”FooBar”/> </Trigger> <Trigger Property=”ItemsControl.AlternationIndex” Value=”1″> <Setter Property=”Background” Value=”Red” TargetName=”FooBar”/> </Trigger> </DataTemplate.Triggers> </DataTemplate> </ItemsControl.ItemTemplate>

How to programmatically select an item in a WPF TreeView?

For those who are still looking for the right solution to this problem here is the one below. I found this one in the comments to the Code Project article “WPF TreeView Selection” http://www.codeproject.com/KB/WPF/TreeView_SelectionWPF.aspx by DaWanderer. It was posted by Kenrae on Nov 25 2008. This worked great for me. Thanks Kenrae! Here is his … Read more

How can a separator be added between items in an ItemsControl

<ItemsControl ItemsSource=”{Binding Numbers}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <!– could use a WrapPanel if more appropriate for your scenario –> <StackPanel Orientation=”Horizontal”/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation=”Horizontal”> <TextBlock x:Name=”commaTextBlock” Text=”, “/> <TextBlock Text=”{Binding .}”/> </StackPanel> <DataTemplate.Triggers> <DataTrigger Binding=”{Binding RelativeSource={RelativeSource PreviousData}}” Value=”{x:Null}”> <Setter Property=”Visibility” TargetName=”commaTextBlock” Value=”Collapsed”/> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> I arrived at your question because I … Read more

Setting Canvas properties in an ItemsControl DataTemplate

The attached properties only work on direct children of the Canvas. ItemsControl will place ContentPresenter controls as its direct children, so you might want to add a style for that as well: <ItemsControl ItemsSource=”{Binding Path=Nodes}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style TargetType=”ContentPresenter”> <Setter Property=”Canvas.Left” Value=”{Binding Path=XPos}” /> <Setter Property=”Canvas.Top” Value=”{Binding Path=YPos}” /> </Style> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)