ComboBox.Template Ignored

Please report bugs here. If you are unsure whether something is a bug or an expected behavior, please post it on the "Technical Support" forum instead, and wait for a moderator to handle/move the post.
TaterJuice
Posts: 147
Joined: Thu Mar 16, 2017 5:40 am
Contact:

ComboBox.Template Ignored

Postby TaterJuice » Fri Jun 30, 2017 8:36 pm

ComboBox Template doesn't appear to work at all. Even replacing it with a simple Textbox appears to do nothing.

Code: Select all

<ComboBox>
    <ComboBox.Template>
        <ControlTemplate
            TargetType="ComboBox">
            <TextBlock
                Text="Hello" />
        </ControlTemplate>
    </ComboBox.Template>
</ComboBox>


Here's what I'm ultimately TRYING to do (based on http://www.eidias.com/Blog/2012/2/20/customizing-wpf-combo-box-style)
(The article uses Template.Triggers and Style.Triggers that will need to be replaced with VisualStates to function completely, since Triggers are not yet supported in CSHTML5)

Code: Select all

<ComboBox>
    <ComboBox.Template>
        <ControlTemplate
            TargetType="ComboBox">
            <Grid>
                <ToggleButton
                    Name="ToggleButton"
                    Template="{StaticResource CBCustomToggleButton}" />
                <ContentPresenter
                    Name="ContentSite"
                    Content="{TemplateBinding ComboBox.SelectionBoxItem}"
                    ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" />
                <TextBox
                    x:Name="PART_EditableTextBox"
                    Foreground="{TemplateBinding Foreground}"
                    IsReadOnly="{TemplateBinding IsReadOnly}"
                    Visibility="Collapsed" />
                <Popup
                    Name="PART_Popup"
                    IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}">
                    <Grid
                        Name="DropDown"
                        MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
                        MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}">
                        <Border
                            Name="DropDownBorder"
                            Background="{TemplateBinding ComboBox.Background}">
                            <ScrollViewer
                                Margin="4,6,4,6">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </Border>
                    </Grid>
                </Popup>
            </Grid>
        </ControlTemplate>
    </ComboBox.Template>
</ComboBox>


Help?

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: ComboBox.Template Ignored

Postby JS-Support @Userware » Sat Aug 19, 2017 6:38 am

Hi,

You need to specify the UseNativeComboBox, like this:

Code: Select all

<ComboBox UseNativeComboBox="False"/>


otherwise the HTML combo box will be used instead.

By the way, here is the default style for the non-native version:

Code: Select all

    <Style x:Key="DefaultComboBoxStyle" TargetType="ComboBox">
        <Setter Property="Background" Value="White"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Padding" Value="6,2,30,2"/>
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <StackPanel>
                        <VisualStateManager.VisualStateGroups>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="OuterBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <ToggleButton x:Name="DropDownToggle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Right" VerticalContentAlignment="Center">
                                    <Path x:Name="arrow" Visibility="Visible" Stroke="Black" Width="13" Height="9" StrokeThickness="3" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Fill" Data="M 1,1.5 L 4.5,5 L 8,1.5"/>
                                </ToggleButton>
                                <ContentPresenter x:Name="ContentPresenter"
                                                  IsHitTestVisible="False"
                                                  Margin="{TemplateBinding Padding}"
                                                  MinHeight="24"/>
                            </Grid>
                        </Border>
                        <Popup x:Name="Popup" IsOpen="False">
                            <Border Background="White" BorderBrush="Black" BorderThickness="1">
                                <ScrollViewer MaxHeight="{TemplateBinding MaxDropDownHeight}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                                    <ItemsPresenter x:Name="ItemsHost" />
                                </ScrollViewer>
                            </Border>
                        </Popup>
                    </StackPanel>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


Thanks.
Regards,
JS-Support

TaterJuice
Posts: 147
Joined: Thu Mar 16, 2017 5:40 am
Contact:

Re: ComboBox.Template Ignored

Postby TaterJuice » Mon Aug 21, 2017 9:48 am

Excellent, thank you!


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 24 guests