Define ControlTemplate in radComboBoxItem Style

2 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    1 posts
    Member since:
    Jan 2012

    Posted 25 Jun 2012 Link to this post

    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>
    

    
    
  2. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 28 Jun 2012 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top