Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have this strange problem with my style for combo box element for a project.

I have a grid that is in a scroll viewer, and an combo box at a fixed place in the grid.
When I click it, it drops itself, but on scrolling simultaneously the grid scrolls its self but the dropped pane of combo sits ideal where it was opened initially.

I've pasted the style what i'm using for my combo box. Hope i get some suggestions to get it fixed.



<Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}">
        <Style.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource DisabledText}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource DisabledBorderBrush}"/>
            </Trigger>
        </Style.Triggers>
        <Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
        <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="100"/>
        <Setter Property="Height" Value="21"/>
        <Setter Property="Foreground" Value="{StaticResource NormalText}"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="FontFamily" Value="{DynamicResource NormalTextFontFamily}"/>
        <Setter Property="FontSize" Value="{DynamicResource NormalTextFontSize}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <Grid>
                        <ToggleButton x:Name="ToggleButton" Template="{StaticResource ComboBoxToggleButton}" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" removed="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"/>
                        <ContentPresenter x:Name="ContentSite" IsHitTestVisible="False" Visibility="Visible" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="6,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left" />
                        <TextBox x:Name="PART_EditableTextBox" Foreground="Silver" Template="{StaticResource ComboBoxTextBox}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="6,8,23,3" Focusable="True" Padding="0" wpf:TextBoxHelper.IsAutoSelectAll="True" removed="Transparent" Visibility="Hidden" IsReadOnly="{TemplateBinding IsReadOnly}" />
                        <Label x:Name="TextPrompt" Content="{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}" Visibility="Collapsed" Focusable="False" Foreground="Silver" HorizontalContentAlignment="Left" Margin="5,0,0,0" VerticalContentAlignment="Center"></Label>
                        <Popup x:Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide" ScrollViewer.CanContentScroll="True">
                            <Grid x:Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}" ScrollViewer.CanContentScroll="True">
                                <Border x:Name="DropDownBorder" removed="{StaticResource NormalBackground}" BorderThickness="1" BorderBrush="{StaticResource SolidBorderBrush}"/>
                                <ScrollViewer Margin="4,4,4,4" SnapsToDevicePixels="True" CanContentScroll="true">
                                    <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
                        </Trigger>

                        <Trigger Property="IsGrouping" Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                        </Trigger>
                        <Trigger SourceName="Popup" Property="AllowsTransparency" Value="true">
                            <Setter TargetName="DropDownBorder" Property="CornerRadius" Value="0"/>
                            <Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
                        </Trigger>
                        <Trigger Property="SelectedIndex" Value="-1" >
                            <Setter TargetName="TextPrompt" Property="Visibility"	Value="Visible"/>
                            <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                        </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>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Background" Value="{DynamicResource NormalBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource SolidBorderBrush}"/>
    </Style>



Regards,
Abhishek
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900