0

I've created template for combobox but it has strange view, data is not displaying:

enter image description here

Here is XAML code:

 <Style TargetType="{x:Type ComboBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBox}">
                <Border Background="{TemplateBinding Background}" x:Name="Bd" BorderBrush="Gray" BorderThickness="2" CornerRadius="2">
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                    <Trigger Property="IsFocused" Value="true">
                        <Setter Property="BorderBrush" Value="Blue" TargetName="Bd"/>
                        <Setter Property="BorderThickness" Value="2"/>
                    </Trigger>
                    <Trigger Property="IsFocused" Value="false">
                        <Setter Property="BorderBrush" Value="Gray" TargetName="Bd"/>
                        <Setter Property="BorderThickness" Value="2"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>

    </Setter>
</Style>

What i missed here?

Timur Mustafaev
  • 4,869
  • 9
  • 63
  • 109
  • 1
    Timur, are you working on a read-only combo to display the lookup data? No element in your template is bound to the selected value of your combobox. You're gonna need a TextBox or a Lable somewhere bound to SelectedItem property. –  Nov 08 '11 at 12:19
  • 1
    You've provided the style, but where is the combobox XAML itself with a content? – sll Nov 08 '11 at 12:19
  • I don't know how to add it)))) – Timur Mustafaev Nov 08 '11 at 12:34

1 Answers1

2

Your template creates near to nothing which makes the default one work, i.e. there is no items popup, and there is no ContentPresenter for the selected item either. Have a look at the default template and you will see exactly what you are missing (Here is a question explaining where to get them).

Community
  • 1
  • 1
H.B.
  • 166,899
  • 29
  • 327
  • 400