none
ComboBox change fontsize of text in TextBox RRS feed

  • Question

  • Hi,

     

    I'm hoping this is a simple question and I'm just overlooking something.  I've created a custom ComboBox to change the fontsize and fontfamily of the combobox items and also the text found within the textbox.  I've been able to change the fontsize and fontfamily of the combobox items, but not the text within the textbox.

    I've added two Setter property statements for FontFamily and FontSize, to no affect.  I've also tried  adding the property statements to the PART_EditableTextBox to no affect.

    I've included my code sample below.  Thanks in advance for any pointers!

     

    Code Snippet

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

    <Border x:Name="PART_ContentHost" Focusable="True" Background="{TemplateBinding Background}"/>

    </ControlTemplate>

     

    <Style x:Key="MyCombobox" TargetType="{x:Type ComboBox}">

    <Setter Property="SnapsToDevicePixels" Value="True" />

    <Setter Property="OverridesDefaultStyle" Value="True" />

    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />

    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />

    <Setter Property="ScrollViewer.CanContentScroll" Value="True" />

    <Setter Property="MinWidth" Value="20" />

    <Setter Property="Height" Value="20" />

    <Setter Property="Foreground" Value="#FF000000" />

    <Setter Property="Background" Value="#FFFFFFFF" />

    <Setter Property="FontFamily" Value="Segoe UI" />

    <Setter Property="FontSize" Value="11" />

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type ComboBox}">

    <Border Name="Combo_border" Background="{TemplateBinding Background}" BorderBrush="{StaticResource controlBorderBrush}" BorderThickness="1" CornerRadius="3">

    <Grid>

    <Border Background="{StaticResource ControlBackgroundGradient}" CornerRadius="3,0,0,3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" Width="Auto" Height="Auto" x:Name="Top_gradient">

    </Border>

    <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="3,1,10,1"

    VerticalAlignment="Center"

    HorizontalAlignment="Left" />

    <TextBox x:Name="PART_EditableTextBox"

    Style="{x:Null}"

    Template="{StaticResource ComboBoxTextBox}"

    HorizontalAlignment="Left"

    VerticalAlignment="Center"

    Margin="3,1,10,1"

    Focusable="True"

    Background="Transparent"

    Visibility="Hidden"

    FontFamily="Segoe UI"

    FontSize="11"

    IsReadOnly="{TemplateBinding IsReadOnly}" />

    <Popup 

    Name="Popup"

    Placement="Bottom"

    IsOpen="{TemplateBinding IsDropDownOpen}"

    AllowsTransparency="True"

    Focusable="False"

    PopupAnimation="Slide">

    <Grid Name="DropDown"

    Margin="0"

    SnapsToDevicePixels="True"

    MinWidth="{TemplateBinding ActualWidth}"

    MaxHeight="{TemplateBinding MaxDropDownHeight}">

    <Border x:Name="DropDownBorder"

    Background="{StaticResource WindowBackgroundBrush}"

    BorderThickness="1"

    BorderBrush="{StaticResource SolidBorderBrush}"

    CornerRadius="2" />

    <ScrollViewer Margin="4,4,4,6" SnapsToDevicePixels="True">

    <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />

    </ScrollViewer>

    </Grid>

    </Popup>

    </Grid>

    </Border>

    <ControlTemplate.Triggers>

    <Trigger Property="HasItems" Value="False">

    <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95" />

    </Trigger>

    <Trigger Property="IsEnabled" Value="False">

    <Setter Property="Background" Value="Transparent" />

    <Setter Property="Foreground" Value="{StaticResource controlDisabledForegroundBrush}" />

    <Setter Property="BorderBrush" TargetName="Combo_border" Value="{StaticResource controlDisabledBorderBrush}" />

    <Setter Property="Visibility" Value="Hidden" TargetName="Top_gradient" />

    </Trigger>

    <Trigger Property="IsGrouping" Value="True">

    <Setter Property="ScrollViewer.CanContentScroll" Value="False" />

    </Trigger>

    <Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="True">

    <Setter TargetName="DropDownBorder" Property="Margin" Value="0,0.5,0,0" />

    </Trigger>

    <Trigger Property="IsEditable" Value="True">

    <Setter Property="IsTabStop" Value="False" />

    <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />

    <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden" />

    </Trigger>

    <Trigger Property="IsKeyboardFocusWithin" Value="True">

    <Setter Property="BorderThickness" Value="2" TargetName="Combo_border" />

    <Setter Property="BorderBrush" Value="#606060" TargetName="Combo_border" />

    <Setter Property="Margin" Value="-1,-1,-1,-1" TargetName="Combo_border" />

    <Setter Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />

    </Trigger>

    </ControlTemplate.Triggers>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    <Style.Triggers>

    </Style.Triggers>

    </Style>

     

    Thursday, June 7, 2007 3:51 PM

Answers

  • you could do somethins like this, Textbox is visible only when IsEditable=true

    <ContentPresenter

    Name="ContentSite"

    IsHitTestVisible="False"

    Content="{TemplateBinding SelectionBoxItem}"

    ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"

    ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"

    Margin="3,3,23,3"

    VerticalAlignment="Center"

    HorizontalAlignment="Left" >

    <ContentPresenter.Resources>

    <Style TargetType="{x:Type TextBlock}">

    <Setter Property="TextBlock.FontSize" Value="20"/>

    </Style>

    </ContentPresenter.Resources>

    </ContentPresenter>

    Thursday, June 7, 2007 4:18 PM
    Moderator

All replies

  • you could do somethins like this, Textbox is visible only when IsEditable=true

    <ContentPresenter

    Name="ContentSite"

    IsHitTestVisible="False"

    Content="{TemplateBinding SelectionBoxItem}"

    ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"

    ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"

    Margin="3,3,23,3"

    VerticalAlignment="Center"

    HorizontalAlignment="Left" >

    <ContentPresenter.Resources>

    <Style TargetType="{x:Type TextBlock}">

    <Setter Property="TextBlock.FontSize" Value="20"/>

    </Style>

    </ContentPresenter.Resources>

    </ContentPresenter>

    Thursday, June 7, 2007 4:18 PM
    Moderator
  • Solution works great!
    Thursday, June 7, 2007 6:52 PM