Skip to main content

Microsoft Silverlight

Answered Question ComboBox Content Stretching... RSS Feed

(0)

BrianGenisio
BrianGen...

Member

Member

26 points

23 Posts

ComboBox Content Stretching...

 I am trying to get the content of my ComboBox to stretch to the size of the DropDown.  I can't, for the life of me, solve this.  What am I missing?

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="30" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <ComboBox x:Name="SearchesComboBox" Width="150">
        <ComboBox.ItemContainerStyle>
            <Style TargetType="ComboBoxItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ComboBox.ItemContainerStyle>
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="Black" BorderThickness="1">
                    <TextBlock Text="{Binding}" Margin="2" />
                </Border>
            </DataTemplate>
        </ComboBox.ItemTemplate>
        <sys:String>Two</sys:String>
        <sys:String>Four</sys:String>
        <sys:String>Six</sys:String>
    </ComboBox>
</Grid>
 

BrianGenisio
BrianGen...

Member

Member

26 points

23 Posts

Answered Question

Re: ComboBox Content Stretching...

 Blah.  I solved my problem.  There is a binding bug in the ListBoxItem template.  I fixed it by copying the template out of the DLL and modifying the ContentPresenter to use a TemplateBinding instead of being hard-coded to "Left".  It sucks, but I don't know of any other way :(

 The full solution is here: http://tinyurl.com/nyusfd

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities