This is a migrated thread and some comments may be shown as answers.

Define ControlTemplate in radComboBoxItem Style

1 Answer 174 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 25 Jun 2012, 07:41 AM
I define a custom style for RadComboBoxItem, i want to change HighlightVisual, so i change the controltemplate.
It's works, but when i specify the DisplayMemberPath in my comboBox, the toString() property is used but not the DisplayMemberPath.
Thanks.

<Style x:Key="RadComboBoxItemStyle"
           TargetType="{x:Type telerik:RadComboBoxItem}">
        <Setter Property="MinHeight"
                Value="19" />
        <Setter Property="Margin"
                Value="0,-1,0,0" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="BorderBrush"
                Value="Transparent" />
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="Padding"
                Value="3,2" />
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="FocusVisualStyle"
                Value="{x:Null}" />       
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type telerik:RadComboBoxItem}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="HighlightVisual">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                                       Storyboard.TargetName="Content">
                                            <DiscreteDoubleKeyFrame KeyTime="0"
                                                                    Value="0.33" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid>
                            <Border x:Name="HighlightVisual"
                                    BorderBrush="{StaticResource ControlFocusedBrush}"
                                    BorderThickness="1"
                                    CornerRadius="0"
                                    Visibility="Collapsed">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1"
                                                         StartPoint="0.5,0">
                                        <GradientStop Color="#FFFFFBDA"
                                                      Offset="0" />
                                        <GradientStop Color="#FFFFFBA3"
                                                      Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <Border BorderBrush="White"
                                        BorderThickness="1"
                                        CornerRadius="0" />
                            </Border>
                            <ContentPresenter x:Name="Content"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              Content="{TemplateBinding Content}"
                                              ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Margin="{TemplateBinding Padding}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


1 Answer, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 28 Jun 2012, 10:09 AM
Hello Benjamin,

I have recreated the issue and noticed that the ContentPresenter seams to be the reason for it.
To resolve it replace the ContentPresenter in your style code with this code:

<ContentPresenter x:Name="Content"
            Margin="{TemplateBinding Padding}"
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

Hope this helps.

Greetings,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ComboBox
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Share this question
or