ComboBox ControlTemplate Question

Hi,

I'm creating my own ComboBox ControlTemplate based on

http://msdn2.microsoft.com/en-us/library/ms752094.aspx

and I'm having a problem with the selected text that goes out of the combo box.

I have already try to put the

Width="{TemplateBinding ActualWidth}"

in the textBox but doesn't seem to work.

Can anyone help me?

Thanks in advance.

Here is the ControlTemplate:

<Stylex:Key="{x:Type Platform_WPF:ComboBoxEx}"TargetType="{x:Type ComboBox}">

<SetterProperty="SnapsToDevicePixels"Value="true"/>

<SetterProperty="OverridesDefaultStyle"Value="false"/>

<SetterProperty="ScrollViewer.HorizontalScrollBarVisibility"Value="Auto"/>

<SetterProperty="ScrollViewer.VerticalScrollBarVisibility"Value="Auto"/>

<SetterProperty="ScrollViewer.CanContentScroll"Value="true"/>

<SetterProperty="MinHeight"Value="20"/>

<SetterProperty="IsEditable"Value="true"/>

<SetterProperty="IsTextSearchEnabled"Value="true"/>

<SetterProperty="Background"Value="{StaticResource WindowBackgroundBrush}"/>

<SetterProperty="BorderBrush"Value="{StaticResource SolidBorderBrush}"/>

<SetterProperty="Template">

<Setter.Value>

<ControlTemplateTargetType="{x:Type Platform_WPF:ComboBoxEx}">

<Grid>

<BorderBackground="{TemplateBinding Background}"

BorderThickness="1"

Name="Border"

BorderBrush="{TemplateBinding BorderBrush}"

CornerRadius="2,2,2,2">

<GridGrid.IsSharedSizeScope="true">

<Grid.ColumnDefinitions>

<ColumnDefinitionWidth="*"/>

<ColumnDefinitionWidth="Auto"/>

</Grid.ColumnDefinitions>

<ToggleButton

Name="ToggleButton"

Template="{StaticResource ComboBoxToggleButton}"

Grid.Column="2"

Focusable="false"

IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"

ClickMode="Press">

</ToggleButton>

<ContentPresenter

Name="ContentSite"

IsHitTestVisible="False"

Content="{TemplateBinding SelectionBoxItem}"

ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"

ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"

Margin="0,0,0,0"

VerticalAlignment="Center"

HorizontalAlignment="Left" />

<TextBoxx:Name="PART_EditableTextBox"

Style="{x:Null}"

Template="{StaticResource ComboBoxTextBox}"

HorizontalAlignment="Left"

VerticalAlignment="Center"

Margin="0,0,0,0"

Focusable="True"

Background="Transparent"

Visibility="Hidden"

IsReadOnly="{TemplateBinding IsReadOnly}"

Width="{TemplateBinding ActualWidth}"/>

</Grid>

</Border>

<Popup

Name="Popup"

Placement="Bottom"

IsOpen="{TemplateBinding IsDropDownOpen}"

AllowsTransparency="True"

Focusable="False"

PopupAnimation="Slide">

<Grid

Name="DropDown"

SnapsToDevicePixels="True"

MinWidth="{TemplateBinding ActualWidth}"

MaxHeight="{TemplateBinding MaxDropDownHeight}">

<Border

x:Name="DropDownBorder"

Background="{StaticResource WindowBackgroundBrush}"

BorderThickness="1"

BorderBrush="{StaticResource SolidBorderBrush}"/>

<ScrollViewerMargin="4,6,4,6"SnapsToDevicePixels="True">

<StackPanelIsItemsHost="True"KeyboardNavigation.DirectionalNavigation="Contained" />

</ScrollViewer>

</Grid>

</Popup>

</Grid>

<ControlTemplate.Triggers>

<TriggerProperty="HasItems"Value="false">

<SetterTargetName="DropDownBorder"Property="MinHeight"Value="95"/>

</Trigger>

<TriggerProperty="IsEnabled"Value="false">

<SetterProperty="Foreground"Value="{StaticResource DisabledForegroundBrush}"/>

</Trigger>

<TriggerProperty="IsGrouping"Value="true">

<SetterProperty="ScrollViewer.CanContentScroll"Value="false"/>

</Trigger>

<TriggerSourceName="Popup"Property="Popup.AllowsTransparency"Value="true">

<SetterTargetName="DropDownBorder"Property="CornerRadius"Value="4"/>

<SetterTargetName="DropDownBorder"Property="Margin"Value="0,2,0,0"/>

</Trigger>

<TriggerProperty="IsEditable"Value="true">

<SetterTargetName="PART_EditableTextBox"Property="Visibility"Value="Visible"/>

<SetterTargetName="ContentSite"Property="Visibility"Value="Hidden"/>

</Trigger>

<TriggerProperty="IsReadOnly"Value="true">

<SetterTargetName="Border"Property="Background"Value="{StaticResource DisabledBackgroundBrush}"/>

<SetterTargetName="Border"Property="BorderBrush"Value="{StaticResource SolidBorderBrush}"/>

</Trigger>

</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

<ControlTemplatex:Key="ComboBoxTextBox"TargetType="{x:Type TextBox}">

<Borderx:Name="PART_ContentHost"Focusable="False"Background="{TemplateBinding Background}" />

</ControlTemplate>

[33875 byte] By [FreedonNadd] at [2008-1-6]

Visual Studio Orcas

Site Classified