Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What is my style missing that I am unable to support DisplayMemberPath correctly? My object is showing as just the namespace and not the display value that it binds to. When I comment out my entire style for combobox & comboboxitem the binding works as intended but I lost the visual the app goes for and need my style. So I have isolated it to it being a problem with the style template.

There is another section to the style for ToggleButton but this is not affecting the problem.

XML
<Style TargetType="{x:Type ComboBoxItem}">
                <Setter Property="UIElement.SnapsToDevicePixels" Value="True"/>
                <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="TextElement.Foreground"  Value="{StaticResource NormalForegroundBrush}"/>
                <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/>
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                            <Border Name="Border" SnapsToDevicePixels="True" Padding="2,2,2,2">
                                <ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" Content="{TemplateBinding ContentControl.Content}" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ComboBoxItem.IsHighlighted" Value="True">
                                    <Setter Property="Panel.Background" TargetName="Border" Value="#FF0BBFAF"/>
                                </Trigger>
                                <Trigger Property="UIElement.IsEnabled" Value="False">
                                    <Setter Property="TextElement.Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


Not working for the items or the combo box

XML
<Style TargetType="{x:Type ComboBox}">
                <Setter Property="UIElement.SnapsToDevicePixels" Value="True"/>
                <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/>
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
                <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
                <Setter Property="TextElement.Foreground" Value="{StaticResource NormalForegroundBrush}"/>
                <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ComboBox">
                            <Grid>
                                <ToggleButton ClickMode="Press" Name="ToggleButton" IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" Focusable="False" Grid.Column="2" Template="{StaticResource ComboBoxToggleButtonTemplate}"/>
                                <ContentPresenter Margin="3,3,23,3" HorizontalAlignment="Left" Name="ContentSite" VerticalAlignment="Center" ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" Content="{TemplateBinding ComboBox.SelectionBoxItem}" IsHitTestVisible="False" />
                                <TextBox Margin="3,3,23,3" Visibility="Hidden" HorizontalAlignment="Left" Name="PART_EditableTextBox" removed="Transparent" VerticalAlignment="Center" Style="{x:Null}" IsReadOnly="False" Focusable="True" xml:space="preserve" Template="{StaticResource ComboBoxTextBoxTemplate}"/>
                                <Popup Placement="Bottom" Name="Popup" Focusable="False" AllowsTransparency="True" IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}" PopupAnimation="Fade"> 
                                    <Grid MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}" Name="DropDown" SnapsToDevicePixels="True"> 
                                        <Border BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="1,1,1,1" Name="DropDownBorder" removed="{StaticResource WindowBackgroundBrush}"/> 
                                        <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
                                        </ScrollViewer>
                                  </Grid>
                                </Popup>
                              </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="ItemsControl.HasItems" Value="False">
                                    <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/>
                                </Trigger>
                                <Trigger Property="UIElement.IsEnabled" Value="False">
                                    <Setter Property="TextElement.Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                                </Trigger>
                                <Trigger Property="ItemsControl.IsGrouping" Value="True">
                                    <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                                </Trigger>
                                <Trigger Property="Window.AllowsTransparency" SourceName="Popup" Value="True">
                                    <Setter Property="Border.CornerRadius" TargetName="DropDownBorder" Value="4"/>
                                    <Setter Property="FrameworkElement.Margin" TargetName="DropDownBorder" Value="0,2,0,0"/>
                                </Trigger>
                                <Trigger Property="ComboBox.IsEditable" Value="True">
                                    <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
                                    <Setter Property="UIElement.Visibility" TargetName="PART_EditableTextBox" Value="Visible"/>
                                    <Setter Property="UIElement.Visibility" TargetName="ContentSite" Value="Hidden"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


Thank you for your help!
Posted
Updated 3-Nov-15 7:09am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900