How can I create a style for the XamComboEditor so it has alternating backbround like the XamDataGrid?
Thanks Andrew! This works totally great for all of my XamCombos now. I have another post which builds on this one where I’m trying to achieve the same mouse over effect in the aero xamdatagrid for the XamCombo’s dropdown list in this post.
http://news.infragistics.com/forums/p/35384/206625.aspx#206625
It seems that I just need to add another setter to the code you already have, but I’m not sure which property to set.
I'm excluding your setter for the Template to reduce the size of the style but basically it would be:
Sorry, I'm having trouble putting the pieces together. Below is a style I use in a resource file which applies to all xamcomboeditors. it rounds the cornders. How would I add your code to this?
<Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="EditTemplate"> <Setter.Value> <ControlTemplate TargetType="{x:Type igEditors:XamComboEditor}"> <Border x:Name="MainBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{DynamicResource StandardControlCornderRadius}"> <!-- SSP 10/3/07 BR25672 Took the Margin="{TemplateBinding Padding}" code out of Border element above since the ComboBox below is already setting its Padding to that value. We don't want to substract the Padding twice. --> <ComboBox Name="PART_FocusSite" Padding="{TemplateBinding Padding}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsReadOnly="{TemplateBinding ReadOnly}" Background="Transparent" BorderBrush="Transparent" BorderThickness="0,0,0,0" ContextMenu="{TemplateBinding ContextMenu}" IsDropDownOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropDownOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{TemplateBinding ComboBoxStyle}" IsEditable="{TemplateBinding IsEditable}" SelectedValuePath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsProvider.ValuePath}" DisplayMemberPath="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsProvider.DisplayMemberPath}" MaxDropDownHeight="{TemplateBinding MaxDropDownHeight}" igEditors:XamComboEditor.ComboEditor="{Binding RelativeSource={RelativeSource TemplatedParent},Path=.}" /> </Border> <!-- SSP 6/6/07 BR23366 Added trigger that sets IsTabStop to False based on IsInEditMode setting. We need this in order to make the Tab and Shift+Tab navigation work properly. Apparently presense of nested textbox causes Shift+Tab to misbehave and cause the framwork to give focus to the parent ContentPresenter if the editor is inside a HeaderedContentControl. This is similar to what inbox ComboBox does. --> <ControlTemplate.Triggers> <Trigger Property="IsInEditMode" Value="True"> <Setter Property="IsTabStop" Value="False" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter></Style>
You changed the Target of the Style. In my snippet, that Style has a TargetType of ComboBox - not XamComboEditor. Then the ComboBoxStyle property of the xamComboEditor is set to that style. If you want to do it this way then your style for XamComboEditor would have 1 setter - one that sets the ComboBoxStyle property and the value would be a StaticResource to the Style that targets ComboBox - that style is the one that has setters for the ItemContainerStyle and the AlternationCount.
I put it in a resource file like this (this way it will automaticaly be used by all xamcombo controls where the window merges this dictionary)
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igwindows="http://infragistics.com/Windows" xmlns:igEditors="http://infragistics.com/Editors" xmlns:luna="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Luna" xmlns:igThemes="http://infragistics.com/Themes">
<Style TargetType="{x:Type igEditors:XamComboEditor}"> <Style.Resources> <AlternationConverter x:Key="BackgroundConverter"> <SolidColorBrush Color="Blue" /> <SolidColorBrush Color="Red" /> </AlternationConverter>
<Style TargetType="ComboBoxItem" x:Key="alternatingItem"> <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex), Converter={StaticResource BackgroundConverter}}"/> </Style> </Style.Resources>
<Setter Property="ItemContainerStyle" Value="{StaticResource alternatingItem}" /> <Setter Property="AlternationCount" Value="2" /></Style>