jumping ListBox

Hi!

I have a little problem creating a custom ListBox in Dec-CTP. To see the problem, just paste the code below into XamlPad.

Problem: Everytime you select an item at the bottom of the ListBox, the ScrollViewer jumps almost to the top :(
Setting CanContentScroll="true" in the Template solves the Problem, but creates other problems in my application, so this solution doesn't help me at all :(

Any tips from you guys how to solve this problem

Michael

<Grid Name="root" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
<Grid.Resources>
<Style x:Key="{x:Type ListBox}" TargetType="{x:Type ListBox}">
    <Setter Property="DefaultStyleKey" Value="{x:Null}" />
    <Setter Property="Background" Value="White" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="BorderBrush" Value="#aa000000" />
    <Setter Property="Padding" Value="2" />
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBox}">
          <Border
      CornerRadius="4"
      Background="{TemplateBinding Background}"
      BorderBrush="{TemplateBinding BorderBrush}"
      BorderThickness="{TemplateBinding BorderThickness}"
      >
            <ScrollViewer
       CanContentScroll="false"
       Margin="1"
       HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
       VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
       Padding="{TemplateBinding Padding}"
       >
              <ItemsPresenter/>
            </ScrollViewer>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="IsEnabled" Value="false">
        <Setter Property="Background" Value="#EEEEEE" />
      </Trigger>
    </Style.Triggers>
  </Style>
    <Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Border CornerRadius="3" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                        <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" HorizontalAlignment="Stretch" Name="ContentSite" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="#eeF5F5FF" />
                <Setter Property="BorderBrush" Value="Silver" />
                <Setter Property="Foreground" Value="Black" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Grid.Resources>
  <ListBox HorizontalAlignment="Center" Height="150">
   <ListBoxItem>Test1</ListBoxItem>
   <ListBoxItem>Test2</ListBoxItem>
   <ListBoxItem>Test3</ListBoxItem>
   <ListBoxItem>Test4</ListBoxItem>
   <ListBoxItem>Test5</ListBoxItem>
   <ListBoxItem>Test6</ListBoxItem>
   <ListBoxItem>Test7</ListBoxItem>
   <ListBoxItem>Test1</ListBoxItem>
   <ListBoxItem>Test2</ListBoxItem>
   <ListBoxItem>Test3</ListBoxItem>
   <ListBoxItem>Test4</ListBoxItem>
   <ListBoxItem>Test5</ListBoxItem>
   <ListBoxItem>Test6</ListBoxItem>
   <ListBoxItem>Test7</ListBoxItem>
   <ListBoxItem>Test1</ListBoxItem>
   <ListBoxItem>Test2</ListBoxItem>
   <ListBoxItem>Test3</ListBoxItem>
   <ListBoxItem>Test4</ListBoxItem>
   <ListBoxItem>Test5</ListBoxItem>
   <ListBoxItem>Test6</ListBoxItem>
   <ListBoxItem>Test7</ListBoxItem>
   <ListBoxItem>Test1</ListBoxItem>
   <ListBoxItem>Test2</ListBoxItem>
   <ListBoxItem>Test3</ListBoxItem>
   <ListBoxItem>Test4</ListBoxItem>
   <ListBoxItem>Test5</ListBoxItem>
   <ListBoxItem>Test6</ListBoxItem>
   <ListBoxItem>Test7</ListBoxItem>
  </ListBox>
</Grid>



Answer this question

jumping ListBox

  • kish75

    Yes, this is an issue in Jan CTP too. This will be fixed in a future release.
  • ghostface039

    This is a known issue with Dec CTP.

    Thanks, John George

    SDE/T, WPF


  • spacemoose

    this is still an issue in Jan CTP, right John

  • tumistry

    It's always good to know it's not my fault :-)

    Michael


  • jumping ListBox